- Title
- List-initialization of references
- Status
- cd2
- Section
- 9.5.5 [dcl.init.list]
- Submitter
- Mike Miller
Created on 2009-07-08.00:00:00 last changed 199 months ago
Messages
Date: 2009-10-15.00:00:00
[Voted into WP at October, 2009 meeting.]
Date: 2009-07-15.00:00:00
Proposed resolution (July, 2009): Move the third bullet of the list in 9.5 [dcl.init] paragraph 16
to the top of the list: If the initializer is a braced-init-list, the
object is list-initialized (9.5.5 [dcl.init.list]). If the destination type is a reference type, see 9.5.4 [dcl.init.ref]. ... Change 9.5.5 [dcl.init.list] paragraph 3, bullets 4 and 5,
as follows: Otherwise, if T is a reference to class
type, or if T is any reference type and the initializer
list has no elements, an rvalue temporary of the type referenced
by T is list-initialized, and the reference is bound to that
temporary. [Note:... Otherwise
(i.e., if T is not an aggregate, class
type, or reference), if the initializer list has a single
element...
Date: 2009-07-08.00:00:00
According to 9.5.5 [dcl.init.list] paragraph 3, This means, for an example like
r1 is bound to a temporary containing the value of
i , not to i itself, which seems surprising. Also,
there's no prohibition here against binding the rvalue reference to an
lvalue, as there is in 9.5.4 [dcl.init.ref] paragraph 5 bullet
2, so the initialization of r2 is well-formed, even though
the corresponding non-list initialization int&& r3(i)
is ill-formed. There's also a question as to whether this bullet even applies to
these examples. According to the decision tree in 9.5 [dcl.init] paragraph 16, initialization of a reference is dispatched
to 9.5.4 [dcl.init.ref] in the first bullet, so these cases
never make it to the third bullet sending the remaining
braced-init-list cases to 9.5.5 [dcl.init.list]. If that's the
correct interpretation, there's a problem with 9.5.4 [dcl.init.ref], since it doesn't deal with the braced-init-list
cases, and the bullet in 9.5.5 [dcl.init.list] paragraph 3
dealing with references is dead code that's never used.
Otherwise, if T is a reference type, an rvalue temporary of
the type referenced by T is list-initialized, and the
reference is bound to that temporary.
int i;
const int& r1{ i };
int&& r2{ i };
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2010-03-29 00:00:00 | admin | set | status: dr -> cd2 |
| 2009-11-08 00:00:00 | admin | set | messages: + msg2464 |
| 2009-11-08 00:00:00 | admin | set | status: ready -> dr |
| 2009-08-03 00:00:00 | admin | set | messages: + msg2169 |
| 2009-07-08 00:00:00 | admin | create | |