]> granicus.if.org Git - clang/commitdiff
<rdar://problem/13278115> Improve diagnostic when failing to bind an rvalue reference...
authorDouglas Gregor <dgregor@apple.com>
Tue, 26 Mar 2013 23:59:23 +0000 (23:59 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 26 Mar 2013 23:59:23 +0000 (23:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178095 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 8516422e4df068d3a20293ec6994e10a40f32fad..63309e376eacf6bc39d144ec0beb62a41c9f2b81 100644 (file)
@@ -3518,6 +3518,14 @@ static void TryReferenceInitializationCore(Sema &S,
       return;
     }
 
+    if ((RefRelationship == Sema::Ref_Compatible ||
+         RefRelationship == Sema::Ref_Compatible_With_Added_Qualification) &&
+        isRValueRef && InitCategory.isLValue()) {
+      Sequence.SetFailed(
+        InitializationSequence::FK_RValueReferenceBindingToLValue);
+      return;
+    }
+
     Sequence.SetFailed(InitializationSequence::FK_ReferenceInitDropsQualifiers);
     return;
   }
index adbdff6efe3c60146ddd94007a459f0024d0082f..812d0de56b941ec32c7c07c7dbffdaff00c263df 100644 (file)
@@ -192,3 +192,11 @@ namespace PR11003 {
     Value y(Move(0));
   }
 }
+
+namespace rdar13278115 {
+  struct X { };
+  struct Y : X { };
+  X &&f0(X &x) { return x; } // expected-error{{rvalue reference to type 'rdar13278115::X' cannot bind to lvalue of type 'rdar13278115::X'}}
+  X &&f1(Y &y) { return y; } // expected-error{{rvalue reference to type 'rdar13278115::X' cannot bind to lvalue of type 'rdar13278115::Y'}}
+  const X &&f2(Y &y) { return y; } // expected-error{{rvalue reference to type 'const rdar13278115::X' cannot bind to lvalue of type 'rdar13278115::Y'}}
+}