<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
This commit is contained in:
Douglas Gregor 2013-03-26 23:59:23 +00:00
Родитель ddb61764ab
Коммит defa32ef4f
2 изменённых файлов: 16 добавлений и 0 удалений

Просмотреть файл

@ -3518,6 +3518,14 @@ static void TryReferenceInitializationCore(Sema &S,
return; 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); Sequence.SetFailed(InitializationSequence::FK_ReferenceInitDropsQualifiers);
return; return;
} }

Просмотреть файл

@ -192,3 +192,11 @@ namespace PR11003 {
Value y(Move(0)); 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'}}
}