Title
Initialization of reference-to-aggregate from designated initializer list
Status
drwp
Section
9.4.5 [dcl.init.list]
Submitter
Richard Smith

Created on 2023-04-06.00:00:00 last changed 11 months ago

Messages

Date: 2023-04-28.19:41:23

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.
Date: 2023-06-15.00:00:00

[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.
History
Date User Action Args
2023-12-19 10:15:28adminsetstatus: dr -> drwp
2023-07-16 13:00:43adminsetstatus: ready -> dr
2023-04-28 19:41:23adminsetstatus: open -> ready
2023-04-08 19:13:08adminsetmessages: + msg7244
2023-04-06 00:00:00admincreate