Issue2267

Title 2267. Copy-initialization of temporary in reference direct-initialization
Status drafting Section 11.6.3 [dcl.init.ref]
Submitter Richard Smith

Created on 2016-05-25.00:00:00 by admin, last changed by admin.

Messages
msg6196 (view) Date: 2018-03-15.00:00:00

Notes from the March, 2018 meeting:

CWG felt that initialization of the temporary should always be copy initialization, regardless of whether the top-level initialization is copy or direct initialization. This would make #2, #3, #5, and #6 all ill-formed.

msg5901 (view) Date: 2018-04-11.00:00:00

Consider the following example:

   struct A {} a; 
   struct B { explicit B(const A&); }; 

   struct D { D(); }; 
   struct C { explicit operator D(); } c; 

   B b1(a);            // #1, ok 
   const B &b2{a};     // #2. ok 
   const B &b3(a);     // #3, error 

   D d1(c);            // ok 
   const D &d2{c};     // ok 
   const D &d3(c);     // #6, ok 

The disparity between #3 and #6 is suprising, as is the difference from #1 and #2. The reason for this difference is in 11.6.4 [dcl.init.list] bullet 3.10:

Otherwise, if T is a reference type, a prvalue of the type referenced by T is generated. The prvalue initializes its result object by copy-list-initialization or direct-list-initialization, depending on the kind of initialization for the reference. The prvalue is then used to direct-initialize the reference.

(reflecting the resolution of issue 1494).

History
Date User Action Args
2018-04-11 00:00:00adminsetstatus: open -> drafting
2018-04-11 00:00:00adminsetmessages: + msg6196
2018-02-27 00:00:00adminsetsection: 8.6.3 [dcl.init.ref] -> 11.6.3 [dcl.init.ref]
2016-05-25 00:00:00admincreate