Almost complete implementation of rvalue references. One bug, and a few unclear areas. Maybe Doug can shed some light on some of the fixmes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67059 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index bfbc6c3..ac0e1e1 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -319,8 +319,16 @@
///
/// \returns A suitable reference type, if there are no
/// errors. Otherwise, returns a NULL type.
-QualType Sema::BuildReferenceType(QualType T, unsigned Quals,
+QualType Sema::BuildReferenceType(QualType T, bool LValueRef, unsigned Quals,
SourceLocation Loc, DeclarationName Entity) {
+ if (LValueRef) {
+ if (const RValueReferenceType *R = T->getAsRValueReferenceType()) {
+ // FIXME: Find the C++0x reference for reference collapsing.
+ // In reference collapsing, lvalue refs win over rvalue refs.
+ return Context.getLValueReferenceType(R->getPointeeType()).
+ getQualifiedType(Quals);
+ }
+ }
if (T->isReferenceType()) {
// C++ [dcl.ref]p4: There shall be no references to references.
//
@@ -367,7 +375,9 @@
Quals &= ~QualType::Volatile;
// Handle restrict on references.
- return Context.getReferenceType(T).getQualifiedType(Quals);
+ if (LValueRef)
+ return Context.getLValueReferenceType(T).getQualifiedType(Quals);
+ return Context.getRValueReferenceType(T).getQualifiedType(Quals);
}
/// \brief Build an array type.
@@ -603,8 +613,8 @@
T = BuildPointerType(T, DeclType.Ptr.TypeQuals, DeclType.Loc, Name);
break;
case DeclaratorChunk::Reference:
- T = BuildReferenceType(T,
- DeclType.Ref.HasRestrict? QualType::Restrict : 0,
+ T = BuildReferenceType(T, DeclType.Ref.LValueRef,
+ DeclType.Ref.HasRestrict ? QualType::Restrict : 0,
DeclType.Loc, Name);
break;
case DeclaratorChunk::Array: {