Created on2011-04-06.00:00:00 last changed136 months ago
[Moved to DR at the September, 2013 meeting.]
Proposed resolution (April, 2013):
Change the two indicated (not contiguous) sub-bullets of9.5.4 [dcl.init.ref] paragraph 5 as follows:
has a class type (i.e.,T2 is a class type), whereT1 is not reference-related toT2, and can beimplicitly converted to an lvalue of type “cv3T3,”...
has a class type (i.e.,T2 is a class type), whereT1 is not reference-related toT2, and can beimplicitly converted to an xvalue, class prvalue, orfunction lvalue of type “cv3T3”, where“cv1T1” is reference-compatible with“cv3T3”(see 12.2.2.7 [over.match.ref]),
Note from the April, 2013 meeting:
Because of concerns about slicing and performance in the February, 2012proposed resolution, CWG decided to return to the August, 2011 proposedresolution and split off the discussion about class prvalues intoissue 1650.
Proposed resolution (February, 2012) [SUPERSEDED]:
Change 9.5.4 [dcl.init.ref] paragraph 5 as follows:
A reference to type “cv1T1” isinitialized by an expression of type “cv2T2” as follows:
If the reference is an lvalue reference and the initializerexpression
is an lvalue (but is not a bit-field), and“cv1T1” is reference-compatible with“cv2T2,” or
has a class type (i.e.,T2 is a class type), whereT1 is not reference-related toT2, and can be
implicitlyconverted to an lvalue of type “cv3T3,” where “cv1T1” isreference-compatible with “cv3T3”106 (this conversion is selected byenumerating the applicable conversion functions (12.2.2.7 [over.match.ref]) and choosing the best one through overloadresolution (12.2 [over.match])),then the reference is bound...
Otherwise, the reference shall be...
If the initializer expression
is an xvalue, class prvalue, array prvalue or functionlvalue and “cv1T1” isreference-compatible with “cv2T2”,or
has a class type (i.e.,T2 is a class type), whereT1 is not reference-related toT2, and can be
implicitlyconverted to an xvalue, classprvalue,or function lvalue of type “cv3T3”, where “cv1T1” isreference-compatible with “cv3T3”(see 12.2.2.7 [over.match.ref]),then the reference is bound... [Example:
struct A { }; struct B : A { } b; extern B f(); const A& rca2 = f(); // bound to theA subobject of theB rvalue. A&& rra = f(); // same as above struct X { operator B(); operator int&(); } x;const A& r = x; // bound to theA subobject of the result of the conversionint i2 = 42; int&& rri = static_cast<int&&>(i2); // bound directly toi2B&& rrb = x; // bound directly to the result ofoperator Bint&& rri2 = X(); // error: lvalue-to-rvalue conversion applied to the // result ofoperator int&—end example]
Otherwise, a temporary... [Example:
const A& r = x; //r refers to a temporary B&& rrb = x; //rrb refers to a temporary const double& rcd2 = 2; //rcd2 refers to temporary with value2.0 double&& rrd = 2; //rrd refers to temporary with value2.0 ...
Change 12.2.2.7 [over.match.ref] paragraph 1 as follows:
Under the conditions specified in 9.5.4 [dcl.init.ref], areference can be bound directly to a glvalue
or classprvaluethat is the result of applying a conversionfunction...
The conversion functions ofS and its base classesare considered, except that for copy-initialization, only thenon-explicit conversion functions are considered. Those that are nothidden withinS and yield type “lvalue reference tocv2T2” (when 9.5.4 [dcl.init.ref]requires an lvalue result) or
“cv2T2” or“rvalue reference tocv2T2” (when 9.5.4 [dcl.init.ref] requires an rvalueresult), where “cv1T” isreference-compatible (9.5.4 [dcl.init.ref]) with“cv2T2”, are candidatefunctions.
Additional note, January, 2012:
Questions have been raised regarding the consistency of thetreatment of class prvalues in this resolution with other types. Theissue is thus being returned to "review" status for additionaldiscussion.
Proposed resolution (August, 2011) [SUPERSEDED]:
Change the two indicated (not contiguous) sub-bullets of9.5.4 [dcl.init.ref] paragraph 5 as follows:
has a class type (i.e.,T2 is a class type), whereT1 is not reference-related toT2, and can beimplicitly converted to an lvalue of type “cv3T3,”...
has a class type (i.e.,T2 is a class type), whereT1 is not reference-related toT2, and can beimplicitly converted to an xvalue, class prvalue, orfunction lvalue of type “cv3T3”, where“cv1T1” is reference-compatible with“cv3T3”(see 12.2.2.7 [over.match.ref]),
In 9.5.5 [dcl.init.list] paragraph 5, both the cases in whicha reference can be bound to the result of a conversion function use thephrase “can be implicitly converted to...” This isconfusing, as it could be read as excludingexplicitconversion functions. However, that appears not to be the intent, as12.2.2.7 [over.match.ref], which is cited in these cases, allowsexplicit conversion functions for direct-initialization.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2014-11-24 00:00:00 | admin | set | status: drwp -> c++14 |
| 2014-03-03 00:00:00 | admin | set | status: dr -> drwp |
| 2013-10-14 00:00:00 | admin | set | messages: +msg4689 |
| 2013-10-14 00:00:00 | admin | set | status: ready -> dr |
| 2013-05-03 00:00:00 | admin | set | messages: +msg4313 |
| 2013-05-03 00:00:00 | admin | set | messages: +msg4312 |
| 2013-05-03 00:00:00 | admin | set | status: review -> ready |
| 2012-09-24 00:00:00 | admin | set | messages: +msg3889 |
| 2012-02-27 00:00:00 | admin | set | messages: +msg3757 |
| 2012-01-17 00:00:00 | admin | set | messages: +msg3602 |
| 2012-01-17 00:00:00 | admin | set | status: ready -> review |
| 2011-04-06 00:00:00 | admin | create | |