Create a new InjectedClassNameType to represent bare-word references to the 
injected class name of a class template or class template partial specialization.
This is a non-canonical type;  the canonical type is still a template 
specialization type.  This becomes the TypeForDecl of the pattern declaration,
which cleans up some amount of code (and complicates some other parts, but
whatever).

Fixes PR6326 and probably a few others, primarily by re-establishing a few
invariants about TypeLoc sizes.     



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98134 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index 9b693af..7f4ad34 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -636,11 +636,16 @@
 
   assert(isInstance() && "No 'this' for static methods!");
 
-  QualType ClassTy;
-  if (ClassTemplateDecl *TD = getParent()->getDescribedClassTemplate())
-    ClassTy = TD->getInjectedClassNameType(C);
-  else
-    ClassTy = C.getTagDeclType(getParent());
+  QualType ClassTy = C.getTypeDeclType(getParent());
+
+  // Aesthetically we prefer not to synthesize a type as the
+  // InjectedClassNameType of a template pattern: injected class names
+  // are printed without template arguments, which might
+  // surprise/confuse/distract our poor users if they didn't
+  // explicitly write one.
+  if (isa<InjectedClassNameType>(ClassTy))
+    ClassTy = cast<InjectedClassNameType>(ClassTy)->getUnderlyingType();
+
   ClassTy = C.getQualifiedType(ClassTy,
                                Qualifiers::fromCVRMask(getTypeQualifiers()));
   return C.getPointerType(ClassTy);