]> granicus.if.org Git - clang/commitdiff
When performing reference binding via a conversion function, perform
authorDouglas Gregor <dgregor@apple.com>
Fri, 21 Jan 2011 00:27:08 +0000 (00:27 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 21 Jan 2011 00:27:08 +0000 (00:27 +0000)
type checking based on the actual reference type we're trying to bind
the result to, rather than stripping the reference.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123950 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp

index 7360eca1e99a5962d7d9fdad8000d7d8685ca520..e25795de40bd2ed54411cae3afa830cf3bf89a78 100644 (file)
@@ -2363,11 +2363,6 @@ static OverloadingResult TryRefInitWithConversionFunction(Sema &S,
     // functions.
     CXXRecordDecl *T2RecordDecl = cast<CXXRecordDecl>(T2RecordType->getDecl());
 
-    // Determine the type we are converting to. If we are allowed to
-    // convert to an rvalue, take the type that the destination type
-    // refers to.
-    QualType ToType = AllowRValues? cv1T1 : DestType;
-
     const UnresolvedSetImpl *Conversions
       = T2RecordDecl->getVisibleConversionFunctions();
     for (UnresolvedSetImpl::const_iterator I = Conversions->begin(),
@@ -2395,10 +2390,10 @@ static OverloadingResult TryRefInitWithConversionFunction(Sema &S,
         if (ConvTemplate)
           S.AddTemplateConversionCandidate(ConvTemplate, I.getPair(),
                                            ActingDC, Initializer,
-                                           ToType, CandidateSet);
+                                           DestType, CandidateSet);
         else
           S.AddConversionCandidate(Conv, I.getPair(), ActingDC,
-                                   Initializer, ToType, CandidateSet);
+                                   Initializer, DestType, CandidateSet);
       }
     }
   }
index f8a13b7c2a7348f9a90c97b3b5687087ca1d0354..4629cb64846b8f29c47bbf9ea9d523eb2ba8efa3 100644 (file)
@@ -22,7 +22,6 @@ struct ConvertsTo {
 
 void test_rvalue_refs() {
   // If the initializer expression...
-
   //   - is an xvalue, class prvalue, array prvalue or function lvalue
   //     and "cv1 T1" is reference-compatible with "cv2 T2", or
 
@@ -54,9 +53,9 @@ void test_rvalue_refs() {
   // class prvalue
   Base&& base6 = ConvertsTo<Base>();
   Base&& base7 = ConvertsTo<Derived>();
-  
-  // FIXME: function lvalue
-  //  int (&&function1)(int) = ConvertsTo<int(&)(int)>();
+
+  // function lvalue
+  int (&&function1)(int) = ConvertsTo<int(&)(int)>();
 }
 
 class NonCopyable {