diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-11-25 06:01:46 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-11-25 06:01:46 +0000 |
commit | d78f598e020c12bf5a8fddc8d08a3be4cff8dc78 (patch) | |
tree | 20697f0673f24300edf7734fd5a47359a7e25cea | |
parent | a0d3ca1ea5578bc736bb71bcec50ab41fefc87b9 (diff) |
Don't crash when we re-use a template specialization node for an explicit instantiation. lib/Support/CommandLine.cpp is our test case
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89845 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaTemplate.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 8ab8d93186..61d73c2dad 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -4106,6 +4106,7 @@ Sema::ActOnExplicitInstantiation(Scope *S, ClassTemplateSpecializationDecl *Specialization = 0; + bool ReusedDecl = false; if (PrevDecl) { bool SuppressNew = false; if (CheckSpecializationInstantiationRedecl(TemplateNameLoc, TSK, @@ -4127,6 +4128,7 @@ Sema::ActOnExplicitInstantiation(Scope *S, Specialization = PrevDecl; Specialization->setLocation(TemplateNameLoc); PrevDecl = 0; + ReusedDecl = true; } } @@ -4164,11 +4166,13 @@ Sema::ActOnExplicitInstantiation(Scope *S, 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 |