CWG Issue 2149 (original) (raw)

This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 117a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-04-13


2149. Brace elision and array length deduction

Section: 9.5.2 [dcl.init.aggr]Status: DRWPSubmitter: Vinny RomanoDate: 2015-06-25

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

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

An array of unknown size initialized with a brace-enclosed initializer-list containingn _initializer-clause_s, where nshall be greater than zero, is defined as having nelements (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-clause_s in the initializer list in a's initializer and two inb'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 void f1(const X(&)[N]); f1({ 1, 2, 3, 4, 5, 6 }); // Is N deduced to 2 or 6?

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

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.