Title
List-initialization of references
Status
c++11
Section
9.4.5 [dcl.init.list]
Submitter
Daniel Krügler

Created on 2010-07-26.00:00:00 last changed 96 months ago

Messages

Date: 2011-03-15.00:00:00

[Voted into the WP at the March, 2011 meeting as part of paper N3262.]

Date: 2010-11-15.00:00:00

Proposed resolution (November, 2010) [SUPERSEDED]:

  1. Change 9.4 [dcl.init] paragraph 16 bullet 1 as follows:

    • If the initializer is a braced-init-list, the object or reference is list-initialized (9.4.5 [dcl.init.list]).

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

    • Otherwise, if the initializer list has a single element, 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.

Date: 2010-07-26.00:00:00

The current wording of the WP appears not to allow for list-initialization of a reference like the following:

    int i;
    int& ir{i};

First, 9.4 [dcl.init] paragraph 16 bullet 1 reads,

  • If the initializer is a braced-init-list, the object is list-initialized (8.5.4).

A reference is not an object, so this does not appear to apply; however, the second bullet sends reference initialization off to 9.4.4 [dcl.init.ref], which does not cover braced-init-lists: paragraph 5 of that section deals only with initilizer expressions, and a braced-init-list is not an expression.

Assuming that the use of “object” in the first bullet is just an oversight, 9.4.5 [dcl.init.list] also does not cover the case of a reference to a scalar type whose initalizer is a braced-init-list with a single element. Bullet 7 of paragraph 3 reads,

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

and would cover this case except that, again, a reference is not an object. As a result, such an initialization would end up in the last bullet and consequently be ill-formed.

Presumably all that is needed is to add “or reference” to the appropriate bullets of 9.4 [dcl.init] paragraph 16 and 9.4.5 [dcl.init.list] paragraph 3.

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: fdis -> c++11
2011-04-10 00:00:00adminsetmessages: + msg3350
2011-04-10 00:00:00adminsetstatus: review -> fdis
2010-11-29 00:00:00adminsetmessages: + msg3094
2010-11-29 00:00:00adminsetstatus: open -> review
2010-07-26 00:00:00admincreate