diff options
author | Douglas Gregor <dgregor@apple.com> | 2013-03-26 23:59:23 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2013-03-26 23:59:23 +0000 |
commit | defa32ef4fdc166d39d2d0859e5edbd78da2ddd0 (patch) | |
tree | 6d577d6302e8cda5e37593f2349f5e182f4654a4 | |
parent | ddb61764abf07ea4580796752d87fda53378ba26 (diff) |
<rdar://problem/13278115> Improve diagnostic when failing to bind an rvalue reference to an lvalue of compatible type.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178095 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaInit.cpp | 8 | ||||
-rw-r--r-- | test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp | 8 |
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 8516422e4d..63309e376e 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -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; } diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp index adbdff6efe..812d0de56b 100644 --- a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp +++ b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp @@ -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'}} +} |