diff options
| author | Douglas Gregor <dgregor@apple.com> | 2011-01-21 00:52:42 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2011-01-21 00:52:42 +0000 |
| commit | 24f2e8ec002a5b0ffaa0fb068b0b36f09d998771 (patch) | |
| tree | e28939388b2786c287a6dc2e30ab690eb72249ae /clang/lib/Sema/SemaInit.cpp | |
| parent | d412fe598be2a31380280fb9012f8876fb099e52 (diff) | |
| download | bcm5719-llvm-24f2e8ec002a5b0ffaa0fb068b0b36f09d998771.tar.gz bcm5719-llvm-24f2e8ec002a5b0ffaa0fb068b0b36f09d998771.zip | |
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.
llvm-svn: 123952
Diffstat (limited to 'clang/lib/Sema/SemaInit.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index e25795de40b..59a39361316 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/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; } |

