Improve the AST representation and semantic analysis for extern
templates. We now distinguish between an explicit instantiation
declaration and an explicit instantiation definition, and know not to
instantiate explicit instantiation declarations. Unfortunately, there
is some remaining confusion w.r.t. instantiation of out-of-line member
function definitions that causes trouble here.
 


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81053 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index 76b6d7e..c243765 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -2934,7 +2934,8 @@
 
   bool SpecializationRequiresInstantiation = true;
   if (PrevDecl) {
-    if (PrevDecl->getSpecializationKind() == TSK_ExplicitInstantiation) {
+    if (PrevDecl->getSpecializationKind() 
+          == TSK_ExplicitInstantiationDefinition) {
       // This particular specialization has already been declared or
       // instantiated. We cannot explicitly instantiate it.
       Diag(TemplateNameLoc, diag::err_explicit_instantiation_duplicate)
@@ -3028,16 +3029,19 @@
   //
   // This check comes when we actually try to perform the
   // instantiation.
+  TemplateSpecializationKind TSK
+    = ExternLoc.isInvalid()? TSK_ExplicitInstantiationDefinition 
+                           : TSK_ExplicitInstantiationDeclaration;
   if (SpecializationRequiresInstantiation)
-    InstantiateClassTemplateSpecialization(Specialization, true);
+    InstantiateClassTemplateSpecialization(Specialization, TSK);
   else // Instantiate the members of this class template specialization.
-    InstantiateClassTemplateSpecializationMembers(TemplateLoc, Specialization);
+    InstantiateClassTemplateSpecializationMembers(TemplateLoc, Specialization,
+                                                  TSK);
 
   return DeclPtrTy::make(Specialization);
 }
 
 // Explicit instantiation of a member class of a class template.
-// FIXME: Implement extern template semantics.
 Sema::DeclResult
 Sema::ActOnExplicitInstantiation(Scope *S, 
                                  SourceLocation ExternLoc,
@@ -3092,17 +3096,21 @@
     }
   }
 
+  TemplateSpecializationKind TSK
+    = ExternLoc.isInvalid()? TSK_ExplicitInstantiationDefinition 
+                           : TSK_ExplicitInstantiationDeclaration;
+  
   if (!Record->getDefinition(Context)) {
     // If the class has a definition, instantiate it (and all of its
     // members, recursively).
     Pattern = cast_or_null<CXXRecordDecl>(Pattern->getDefinition(Context));
     if (Pattern && InstantiateClass(TemplateLoc, Record, Pattern, 
                                     getTemplateInstantiationArgs(Record),
-                                    /*ExplicitInstantiation=*/true))
+                                    TSK))
       return true;
   } else // Instantiate all of the members of the class.
     InstantiateClassMembers(TemplateLoc, Record, 
-                            getTemplateInstantiationArgs(Record));
+                            getTemplateInstantiationArgs(Record), TSK);
 
   // FIXME: We don't have any representation for explicit instantiations of
   // member classes. Such a representation is not needed for compilation, but it