Movatterモバイル変換


[0]ホーム

URL:


Issue 1287 - WG21 CWG Issues
Title
Direct initialization vs “implicit” conversion in reference binding
Status
c++14
Section
9.5.4 [dcl.init.ref]
Submitter
Daniel Krügler

Created on2011-04-06.00:00:00 last changed136 months ago

Messages

msg4689 (view)
Date: 2013-09-15.00:00:00

[Moved to DR at the September, 2013 meeting.]

msg4313 (view)
Date: 2013-04-15.00:00:00

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]),

msg4312 (view)
Date: 2013-04-15.00:00:00

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.

msg3889 (view)
Date: 2012-02-15.00:00:00

Proposed resolution (February, 2012) [SUPERSEDED]:

  1. Change 9.5.4 [dcl.init.ref] paragraph 5 as follows:

  2. 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 beimplicitly converted to an lvalue of type “cv3T3,” where “cv1T1” isreference-compatible with “cv3T3106 (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 beimplicitly converted 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 conversion  int i2 = 42;  int&& rri = static_cast<int&&>(i2); // bound directly toi2  B&& rrb = x;            // bound directly to the result ofoperator B  int&& 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  ...
  3. Change 12.2.2.7 [over.match.ref] paragraph 1 as follows:

  4. Under the conditions specified in 9.5.4 [dcl.init.ref], areference can be bound directly to a glvalueor classprvalue that 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) orcv2T2” 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.

msg3757 (view)
Date: 2012-09-24.00:00:00

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.

msg3602 (view)
Date: 2011-08-15.00:00:00

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]),

msg3470 (view)
Date: 2012-09-24.00:00:00

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
DateUserActionArgs
2014-11-24 00:00:00adminsetstatus: drwp -> c++14
2014-03-03 00:00:00adminsetstatus: dr -> drwp
2013-10-14 00:00:00adminsetmessages: +msg4689
2013-10-14 00:00:00adminsetstatus: ready -> dr
2013-05-03 00:00:00adminsetmessages: +msg4313
2013-05-03 00:00:00adminsetmessages: +msg4312
2013-05-03 00:00:00adminsetstatus: review -> ready
2012-09-24 00:00:00adminsetmessages: +msg3889
2012-02-27 00:00:00adminsetmessages: +msg3757
2012-01-17 00:00:00adminsetmessages: +msg3602
2012-01-17 00:00:00adminsetstatus: ready -> review
2011-04-06 00:00:00admincreate

[8]ページ先頭

©2009-2026 Movatter.jp