[cfe-commits] r89845 - /cfe/trunk/lib/Sema/SemaTemplate.cpp

Douglas Gregor dgregor at apple.com
Tue Nov 24 22:01:46 PST 2009


Author: dgregor
Date: Wed Nov 25 00:01:46 2009
New Revision: 89845

URL: http://llvm.org/viewvc/llvm-project?rev=89845&view=rev
Log:
Don't crash when we re-use a template specialization node for an explicit instantiation. lib/Support/CommandLine.cpp is our test case

Modified:
    cfe/trunk/lib/Sema/SemaTemplate.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=89845&r1=89844&r2=89845&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Nov 25 00:01:46 2009
@@ -4106,6 +4106,7 @@
   
   ClassTemplateSpecializationDecl *Specialization = 0;
 
+  bool ReusedDecl = false;
   if (PrevDecl) {
     bool SuppressNew = false;
     if (CheckSpecializationInstantiationRedecl(TemplateNameLoc, TSK,
@@ -4127,6 +4128,7 @@
       Specialization = PrevDecl;
       Specialization->setLocation(TemplateNameLoc);
       PrevDecl = 0;
+      ReusedDecl = true;
     }
   }
   
@@ -4164,11 +4166,13 @@
   Specialization->setTypeAsWritten(WrittenTy);
   TemplateArgsIn.release();
 
-  // Add the explicit instantiation into its lexical context. However,
-  // since explicit instantiations are never found by name lookup, we
-  // just put it into the declaration context directly.
-  Specialization->setLexicalDeclContext(CurContext);
-  CurContext->addDecl(Specialization);
+  if (!ReusedDecl) {
+    // Add the explicit instantiation into its lexical context. However,
+    // since explicit instantiations are never found by name lookup, we
+    // just put it into the declaration context directly.
+    Specialization->setLexicalDeclContext(CurContext);
+    CurContext->addDecl(Specialization);
+  }
 
   // C++ [temp.explicit]p3:
   //   A definition of a class template or class member template





More information about the cfe-commits mailing list