Movatterモバイル変換


[0]ホーム

URL:


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

2025-12-20


2149. Brace elision and array length deduction

Section:9.5.2  [dcl.init.aggr]    Status:CD7    Submitter:Vinny Romano    Date: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 abrace-enclosedinitializer-list containingninitializer-clauses, wherenshall be greater than zero, is defined as havingnelements (9.3.4.5 [dcl.array]).

However, the interaction of this with brace elision is notclear. 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 andb are said to have the same value,even though there are sixinitializer-clauses in theinitializer list ina's initializer and two inb's initializer.

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

in theP'[N] case, ifN 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 }); // IsN deduced to2 or6?  template<int N> void f2(const X(&)[N][2]);  f2({ 1, 2, 3, 4, 5, 6 }); // IsN deduced to1 or6?

Additional notes (April, 2024)

The situation with arrays of unknown bound was clarified byP3106R1. The concern about template argument deduction was leftuntouched; the existing wording in 13.10.3.2 [temp.deduct.call] paragraph 1 seems to be clear, rendering the two examples shown aboveill-formed, because deduction of P' against the integer argumentsfails.




[8]ページ先頭

©2009-2026 Movatter.jp