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

2024-04-18


2319. Nested brace initialization from same type

Section: 12.2.4.2  [over.best.ics]     Status: drafting     Submitter: Richard Smith     Date: 2016-09-06

Consider:

  struct A { A(); } a;
  A a1 = {a}, a2 = {{a}}, a3 = {{{a}}};

a1 and a2 are valid, a3 is ill-formed, because 12.2.4.2 [over.best.ics] bullet 4.5 allows one pair of braces and 12.2.4.2.6 [over.ics.list] paragraph 2 allows a second pair of braces. The implicit conversion sequence from {{a}} to A is a user-defined conversion.

Prior to the list-initialization-from-same-type changes via issues 1467 and 2076, a2 was ill-formed like a3.

Is this intended, or did DR2076 not go far enough in reintroducing the restriction? Perhaps a more extreme rule, such as saying that a copy/move constructor is simply not a candidate for list-initialization from a list that contains one element that is itself a list, would work better?

Notes from the July, 2017 meeting:

CWG agreed that the a2 example should be ill-formed but that the a1 example must remain for C compatibility.