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


2713. Initialization of reference-to-aggregate from designated initializer list

Section: 9.4.5  [dcl.init.list]     Status: DRWP     Submitter: Richard Smith     Date: 2023-04-06

[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:

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):

  1. 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. ...
    • ...
  2. 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 ...
  3. 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 ]
  4. 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.