aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaInit.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-01-21 00:52:42 +0000
committerDouglas Gregor <dgregor@apple.com>2011-01-21 00:52:42 +0000
commitb2855ad68d93824faf47c09bbef90ba74157f0f4 (patch)
treef97eb5557e3ec55a462d4b776e7f712c4458ddda /lib/Sema/SemaInit.cpp
parent564cb06b1f010ab3c5e316ac79ba6cfdd72e9c1d (diff)
More work to bring reference binding up to the latest C++0x
specification. In particular, an rvalue reference can bind to an initializer expression that is an lvalue if the referent type and the initializer expression type are not reference-related. This is a newer formulation to the previous "rvalue references can never bind to lvalues" rule. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123952 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaInit.cpp')
-rw-r--r--lib/Sema/SemaInit.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index e25795de40..59a3936131 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -2571,23 +2571,19 @@ static void TryReferenceInitialization(Sema &S,
// - Otherwise, the reference shall be an lvalue reference to a
// non-volatile const type (i.e., cv1 shall be const), or the reference
// shall be an rvalue reference.
- if (!((isLValueRef && T1Quals.hasConst() && !T1Quals.hasVolatile()) ||
- (isRValueRef && InitCategory.isRValue()))) {
+ if (isLValueRef && !(T1Quals.hasConst() && !T1Quals.hasVolatile())) {
if (S.Context.getCanonicalType(T2) == S.Context.OverloadTy)
Sequence.SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
else if (ConvOvlResult && !Sequence.getFailedCandidateSet().empty())
Sequence.SetOverloadFailure(
InitializationSequence::FK_ReferenceInitOverloadFailed,
ConvOvlResult);
- else if (isLValueRef)
+ else
Sequence.SetFailed(InitCategory.isLValue()
? (RefRelationship == Sema::Ref_Related
? InitializationSequence::FK_ReferenceInitDropsQualifiers
: InitializationSequence::FK_NonConstLValueReferenceBindingToUnrelated)
: InitializationSequence::FK_NonConstLValueReferenceBindingToTemporary);
- else
- Sequence.SetFailed(
- InitializationSequence::FK_RValueReferenceBindingToLValue);
return;
}
@@ -2696,6 +2692,15 @@ static void TryReferenceInitialization(Sema &S,
return;
}
+ // [...] If T1 is reference-related to T2 and the reference is an rvalue
+ // reference, the initializer expression shall not be an lvalue.
+ if (RefRelationship >= Sema::Ref_Related && !isLValueRef &&
+ InitCategory.isLValue()) {
+ Sequence.SetFailed(
+ InitializationSequence::FK_RValueReferenceBindingToLValue);
+ return;
+ }
+
Sequence.AddReferenceBindingStep(cv1T1, /*bindingTemporary=*/true);
return;
}