Title
Brace elision and array length deduction
Status
drwp
Section
9.4.2 [dcl.init.aggr]
Submitter
Vinny Romano

Created on 2015-06-25.00:00:00 last changed 5 months ago

Messages

Date: 2024-04-15.00:00:00

Additional notes (April, 2024)

The situation with arrays of unknown bound was clarified by P3106R1. The concern about template argument deduction was left untouched; the existing wording in 13.10.3.2 [temp.deduct.call] paragraph 1 seems to be clear, rendering the two examples shown above ill-formed, because deduction of P' against the integer arguments fails.

Date: 2024-03-15.00:00:00

[Accepted as a DR as paper P3106R1 at the March, 2024 meeting.]

According to 9.4.2 [dcl.init.aggr] paragraph 4,

An array of unknown size initialized with a brace-enclosed initializer-list containing n initializer-clauses, where n shall be greater than zero, is defined as having n elements (9.3.4.5 [dcl.array]).

However, the interaction of this with brace elision is not clear. For instance, in the example in paragraph 7,

  struct X { int i, j, k = 42; };
  X a[] = { 1, 2, 3, 4, 5, 6 };
  X b[2] = { { 1, 2, 3 }, { 4, 5, 6 } };

a and b are said to have the same value, even though there are six initializer-clauses in the initializer list in a's initializer and two in b's initializer.

Similarly, 13.10.3.2 [temp.deduct.call] paragraph 1 says,

in the P'[N] case, if N is a non-type template parameter, N is deduced from the length of the initializer list

Should that take into account the underlying type of the array? For example,

  template<int N> void f1(const X(&)[N]);
  f1({ 1, 2, 3, 4, 5, 6 }); // Is N deduced to 2 or 6?

  template<int N> void f2(const X(&)[N][2]);
  f2({ 1, 2, 3, 4, 5, 6 }); // Is N deduced to 1 or 6?
History
Date User Action Args
2024-07-20 13:52:34adminsetstatus: dr -> drwp
2024-04-25 10:46:20adminsetmessages: + msg7674
2024-04-24 16:13:19adminsetstatus: drafting -> dr
2015-06-25 00:00:00admincreate