Title
Reference list initialization
Status
cd3
Section
9.4.5 [dcl.init.list]
Submitter
Daniel Krügler

Created on 2011-04-06.00:00:00 last changed 131 months ago

Messages

Date: 2012-02-15.00:00:00

[Voted into the WP at the February, 2012 meeting; moved to DR at the October, 2012 meeting.]

Date: 2011-08-15.00:00:00

Proposed resolution (August, 2011):

Change 9.4.5 [dcl.init.list] paragraph 3 as follows:

  • ...

  • Otherwise, if T is a class type, constructors are considered...

  • Otherwise, if T is a reference type, a prvalue temporary of the type referenced by T is list-initialized, and the reference is bound to that temporary. [Note: As usual, the binding will fail and the program is ill-formed if the reference type is an lvalue reference to a non-const type. —end note] [Example: ... —end example]

  • Otherwise, if the initializer list has a single element of type E and either T is not a reference type or its referenced type is reference-related to E, the object or reference is initialized from that element; if a narrowing conversion (see below) is required to convert the element to T, the program is ill-formed. [Example:...

  • Otherwise, if T is a reference type, a prvalue temporary of the type referenced by T is list-initialized, and the reference is bound to that temporary. [Note: As usual, the binding will fail and the program is ill-formed if the reference type is an lvalue reference to a non-const type. —end note] [Example: ... —end example]

  • Otherwise, if the initializer list has no elements...

  • ...

Date: 2012-09-24.00:00:00

One might expect that in an example like

  int i;
  int & ir{i};

ir would bind directly to i. However, according to 9.4.5 [dcl.init.list] paragraph 3, this example creates a temporary of type int and binds the reference to that temporary:

  • ...

  • Otherwise, if T is a reference type, a prvalue temporary of the type referenced by T is list-initialized, and the reference is bound to that temporary...

  • Otherwise, if the initializer list has a single element, the object or reference is initialized from that element...

Also, the “or reference” in the last bullet is dead code, as a reference initialization is always handled by the preceding bullet.

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: drwp -> cd3
2012-11-03 00:00:00adminsetstatus: dr -> drwp
2012-09-24 00:00:00adminsetmessages: + msg4009
2012-02-27 00:00:00adminsetmessages: + msg3819
2012-02-27 00:00:00adminsetstatus: ready -> dr
2011-04-06 00:00:00admincreate