Track a class template specialization's point of instantiation separately
from its location.  Initialize appropriately.

When implicitly creating a declaration of a class template specialization
after encountering the first reference to it, use the pattern class's
location instead of the location of the first reference.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81515 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index 63c29de..8bb33eb 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -1097,7 +1097,7 @@
       // the set of specializations.
       Decl = ClassTemplateSpecializationDecl::Create(Context,
                                     ClassTemplate->getDeclContext(),
-                                    TemplateLoc,
+                                    ClassTemplate->getLocation(),
                                     ClassTemplate,
                                     Converted, 0);
       ClassTemplate->getSpecializations().InsertNode(Decl, InsertPos);
@@ -3027,6 +3027,8 @@
   Specialization->setLexicalDeclContext(CurContext);
   CurContext->addDecl(Specialization);
 
+  Specialization->setPointOfInstantiation(TemplateNameLoc);
+
   // C++ [temp.explicit]p3:
   //   A definition of a class template or class member template
   //   shall be in scope at the point of the explicit instantiation of
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index e719bbd..6a52352 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -895,7 +895,7 @@
   // Note that this is an instantiation.
   ClassTemplateSpec->setSpecializationKind(TSK);
 
-  bool Result = InstantiateClass(ClassTemplateSpec->getLocation(),
+  bool Result = InstantiateClass(ClassTemplateSpec->getPointOfInstantiation(),
                                  ClassTemplateSpec, Pattern,
                               getTemplateInstantiationArgs(ClassTemplateSpec),
                                  TSK,
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 9f95198..bbcb1a4 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -1784,10 +1784,8 @@
     if (ClassTemplateSpecializationDecl *ClassTemplateSpec
           = dyn_cast<ClassTemplateSpecializationDecl>(Record->getDecl())) {
       if (ClassTemplateSpec->getSpecializationKind() == TSK_Undeclared) {
-        // Update the class template specialization's location to
-        // refer to the point of instantiation.
         if (Loc.isValid())
-          ClassTemplateSpec->setLocation(Loc);
+          ClassTemplateSpec->setPointOfInstantiation(Loc);
         return InstantiateClassTemplateSpecialization(ClassTemplateSpec,
                                                       TSK_ImplicitInstantiation,
                                                       /*Complain=*/diag != 0);