Track source information for template arguments and template specialization
types.  Preserve it through template instantiation.  Preserve it through PCH,
although TSTs themselves aren't serializable, so that's pretty much meaningless.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85500 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 50b0fb8..0b54533 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -886,14 +886,13 @@
   // FIXME: Do we actually want to perform substitution here? I don't think
   // we do.
   if (D->hasDefaultArgument()) {
-    QualType DefaultPattern = D->getDefaultArgument();
-    QualType DefaultInst
+    DeclaratorInfo *DefaultPattern = D->getDefaultArgumentInfo();
+    DeclaratorInfo *DefaultInst
       = SemaRef.SubstType(DefaultPattern, TemplateArgs,
                           D->getDefaultArgumentLoc(),
                           D->getDeclName());
 
     Inst->setDefaultArgument(DefaultInst,
-                             D->getDefaultArgumentLoc(),
                              D->defaultArgumentWasInherited() /* preserve? */);
   }
 
@@ -1026,16 +1025,15 @@
   
   // Substitute into the template arguments of the class template partial
   // specialization.
-  const TemplateArgumentList &PartialSpecTemplateArgs 
-    = PartialSpec->getTemplateInstantiationArgs();
-  llvm::SmallVector<TemplateArgument, 4> InstTemplateArgs;
-  for (unsigned I = 0, N = PartialSpecTemplateArgs.size(); I != N; ++I) {
-    TemplateArgument Inst = SemaRef.Subst(PartialSpecTemplateArgs[I], 
-                                          TemplateArgs);
-    if (Inst.isNull())
+  const TemplateArgumentLoc *PartialSpecTemplateArgs
+    = PartialSpec->getTemplateArgsAsWritten();
+  unsigned N = PartialSpec->getNumTemplateArgsAsWritten();
+
+  llvm::SmallVector<TemplateArgumentLoc, 4> InstTemplateArgs(N);
+  for (unsigned I = 0; I != N; ++I) {
+    if (SemaRef.Subst(PartialSpecTemplateArgs[I], InstTemplateArgs[I],
+                      TemplateArgs))
       return true;
-    
-    InstTemplateArgs.push_back(Inst);
   }
   
 
@@ -1116,6 +1114,8 @@
                                                      InstParams,
                                                      ClassTemplate, 
                                                      Converted,
+                                                     InstTemplateArgs.data(),
+                                                     InstTemplateArgs.size(),
                                                      0);
   InstPartialSpec->setInstantiatedFromMember(PartialSpec);
   InstPartialSpec->setTypeAsWritten(WrittenTy);