Implement C++ DR 106 and C++ DR 540, both of which deal with
reference-collapsing. 

Implement diagnostic for formation of a reference to cv void.

Drop cv-qualifiers added to a reference type when the reference type
comes from a typedef.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58612 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 7a84171..f414f16 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -1222,6 +1222,19 @@
     // Recursively parse the declarator.
     ParseDeclaratorInternal(D);
 
+    if (D.getNumTypeObjects() > 0) {
+      // C++ [dcl.ref]p4: There shall be no references to references.
+      DeclaratorChunk& InnerChunk = D.getTypeObject(D.getNumTypeObjects() - 1);
+      if (InnerChunk.Kind == DeclaratorChunk::Reference) {
+        Diag(InnerChunk.Loc, diag::err_illegal_decl_reference_to_reference,
+             D.getIdentifier() ? D.getIdentifier()->getName() : "type name");
+
+        // Once we've complained about the reference-to-referwnce, we
+        // can go ahead and build the (technically ill-formed)
+        // declarator: reference collapsing will take care of it.
+      }
+    }
+
     // Remember that we parsed a reference type. It doesn't have type-quals.
     D.AddTypeInfo(DeclaratorChunk::getReference(DS.getTypeQualifiers(), Loc,
                                                 DS.TakeAttributes()));