Title
Parenthesized initialization of reference-to-aggregate
Status
nad
Section
9.4.1 [dcl.init.general]
Submitter
Mike Miller

Created on 2023-03-14.00:00:00 last changed 18 months ago

Messages

Date: 2023-03-15.00:00:00

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.

Date: 2023-03-19.19:31:47

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.

History
Date User Action Args
2023-05-11 19:59:31adminsetstatus: open -> nad
2023-03-16 23:18:20adminsetmessages: + msg7233
2023-03-14 00:00:00admincreate