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

2024-03-20


2709. Parenthesized initialization of reference-to-aggregate

Section: 9.4.1  [dcl.init.general]     Status: NAD     Submitter: Mike Miller     Date: 2023-03-14     Liaison: EWG

Paper P0960R3 enabled initialization of aggregates (including arrays) from parenthesized expression lists. The rather similar case of initializating a reference to an aggregate was not addressed. For example:

  const int (&ra)[2](1,2);

There is no evidence in 9.4.1 [dcl.init.general] paragraph 16 that such support is intended, nor does 9.4.4 [dcl.init.ref] paragraph 5 admit an initializer other than a (single) expression for a reference.

There is implementation divergence: gcc accepts, others reject. Also, the parenthesized aggregate initialization paper P0960R3 apparently originally envisioned a textual transformation to a braced-init-list, which presumably would have permitted the example. It is not clear whether the reference case was intentionally or accidentially dropped during the multiple revisions of the paper.

Additional notes (March, 2023)

Forwarded to EWG for consideration via cplusplus/papers#1494 by decision of the CWG chair.

EWG 2023-05-11

It was noted that an attempt to initialize a reference-to-class type using a parenthesized expression-list is also ill-formed even if the class has a suitable constructor. Since parenthesized aggregate initialization was modeled after a constructor invocation for aspects such as temporary lifetimes, the status quo seems consistent in that regard.