summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-11-25 06:01:46 +0000
committerDouglas Gregor <dgregor@apple.com>2009-11-25 06:01:46 +0000
commit0681a35f5f8fb693d0af2ef8e6bbfc9efa4ae9f1 (patch)
treea45192561304d2b8ca115bc5087697055023d032
parent2b8fed15e0766540fcd575bca4ce4318f1d8604b (diff)
downloadbcm5719-llvm-0681a35f5f8fb693d0af2ef8e6bbfc9efa4ae9f1.tar.gz
bcm5719-llvm-0681a35f5f8fb693d0af2ef8e6bbfc9efa4ae9f1.zip
Don't crash when we re-use a template specialization node for an explicit instantiation. lib/Support/CommandLine.cpp is our test case
llvm-svn: 89845
-rw-r--r--clang/lib/Sema/SemaTemplate.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 8ab8d93186a..61d73c2dad1 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/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
OpenPOWER on IntegriCloud