Give explicit and implicit instantiations of static data members of
class templates the proper linkage. 

Daniel, please look over the CodeGenModule bits.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84140 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 28c0fa6..060cc55 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1191,14 +1191,14 @@
   }
 
   // Never instantiate an explicit specialization.
-  if (Def->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
+  if (Var->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
     return;
   
   // C++0x [temp.explicit]p9:
   //   Except for inline functions, other explicit instantiation declarations
   //   have the effect of suppressing the implicit instantiation of the entity
   //   to which they refer.
-  if (Def->getTemplateSpecializationKind() 
+  if (Var->getTemplateSpecializationKind() 
         == TSK_ExplicitInstantiationDeclaration)
     return;
 
@@ -1218,12 +1218,14 @@
   DeclContext *PreviousContext = CurContext;
   CurContext = Var->getDeclContext();
 
+  VarDecl *OldVar = Var;
   Var = cast_or_null<VarDecl>(SubstDecl(Def, Var->getDeclContext(),
                                           getTemplateInstantiationArgs(Var)));
-
   CurContext = PreviousContext;
 
   if (Var) {
+    Var->setPreviousDeclaration(OldVar);
+    Var->setTemplateSpecializationKind(OldVar->getTemplateSpecializationKind());
     DeclGroupRef DG(Var);
     Consumer.HandleTopLevelDecl(DG);
   }