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

2024-11-11


1505. Direct binding of reference to temporary in list-initialization

Section: 9.4.5  [dcl.init.list]     Status: dup     Submitter: Steve Adamczyk     Date: 2012-05-27

In an example like

  const int&r {1};

the expectation is that this creates a temporary of type const int containing the value 1 and binds the reference to it. And it does, but along the way it creates two temporaries. The wording in 9.4.5 [dcl.init.list] paragraph 3, the bullet on reference initialization, says that a prvalue temporary of type const int is created, and then we do reference binding. Because this is a non-class case and the source is a prvalue, we end up in the section of 9.4.4 [dcl.init.ref] that says we create a temporary (again of type const int) and initialize it from the source. So we've created two temporaries. Now, this may not matter to anyone, since the discarded temporary is not observable, but it may be a concern that the reference is not binding directly to the temporary created for the {1}, since we do sometimes base behavior on the “bind directly” attribute.

Rationale (September, 2012):

This issue is based on the wording prior to the application of the resolution of issue 1288. With that change, there is no longer a problem.