This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-11-11
[Accepted as a DR at the June, 2023 meeting.]
Aggregates can be initialized by a designated initializer list, but references to aggregates cannot, although list-initialization of such with a regular braced-init-list is fine.
Subclause 9.4.5 [dcl.init.list] paragraph 3 specifies:
List-initialization of an object or reference of type T is defined as follows:
- If the braced-init-list contains a designated-initializer-list, T shall be an aggregate class. ...
- ...
- Otherwise, if T is a reference type, a prvalue is generated. The prvalue initializes its result object by copy-list-initialization from the initializer list. The prvalue is then used to direct-initialize the reference. The type of the prvalue is the type referenced by T, unless ...
- ...
Subclause 12.2.4.2.6 [over.ics.list] paragraph 2 specifies:
If the initializer list is a designated-initializer-list, a conversion is only possible if the parameter has an aggregate type that can be initialized from the initializer list according to the rules for aggregate initialization (9.4.2 [dcl.init.aggr]), in which case the implicit conversion sequence is a user-defined conversion sequence whose second standard conversion sequence is an identity conversion.
Proposed resolution (approved by CWG 2023-04-28):
Change in 9.4.5 [dcl.init.list] bullet 3.1 as follows:
- If the braced-init-list contains a designated-initializer-list and T is not a reference type, T shall be an aggregate class. ...
- ...
Change in 9.4.5 [dcl.init.list] bullet 3.9 as follows:
Otherwise, if the initializer list is not a designated-initializer-list and has a single element of type E and ...
Change in 9.4.5 [dcl.init.list] bullet 3.10 as follows:
[ Example:... const B& b2{a}; // error: cannot copy-list-initialize B temporary from A struct C { int x; }; C&& c = { .x = 1 }; // OK-- end example ]
Change in 12.2.4.2.6 [over.ics.list] paragraph 2 as follows:
If the initializer list is a designated-initializer-list and the parameter is not a reference, a conversion is only possible if the parameter has an aggregate type that can be initialized from the initializer list according to the rules for aggregate initialization (9.4.2 [dcl.init.aggr]), in which case the implicit conversion sequence is a user-defined conversion sequence whose second standard conversion sequence is an identity conversion.