aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-09-10 00:12:48 +0000
committerDouglas Gregor <dgregor@apple.com>2009-09-10 00:12:48 +0000
commit1cdcc579df30dba1b2e1e9909125bb9c61898e05 (patch)
tree673f473def8c90dedbe4a2304e778d8172715f23
parentf8d8d1a99b802b8e9f2e7da441b64096b89f133d (diff)
When re-entering a template scope, we may be entering a class template
partial specialization rather than a subclass of TemplateDecl. Fixes a crash in libstdc++ 4.2's <map>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81407 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDeclCXX.cpp14
-rw-r--r--test/SemaTemplate/nested-template.cpp10
2 files changed, 21 insertions, 3 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 8fd3a70116..b3cef85d67 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -1858,11 +1858,19 @@ void Sema::AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl) {
}
void Sema::ActOnReenterTemplateScope(Scope *S, DeclPtrTy TemplateD) {
- TemplateDecl *Template = TemplateD.getAs<TemplateDecl>();
- if (!Template)
+ Decl *D = TemplateD.getAs<Decl>();
+ if (!D)
+ return;
+
+ TemplateParameterList *Params = 0;
+ if (TemplateDecl *Template = dyn_cast<TemplateDecl>(D))
+ Params = Template->getTemplateParameters();
+ else if (ClassTemplatePartialSpecializationDecl *PartialSpec
+ = dyn_cast<ClassTemplatePartialSpecializationDecl>(D))
+ Params = PartialSpec->getTemplateParameters();
+ else
return;
- TemplateParameterList *Params = Template->getTemplateParameters();
for (TemplateParameterList::iterator Param = Params->begin(),
ParamEnd = Params->end();
Param != ParamEnd; ++Param) {
diff --git a/test/SemaTemplate/nested-template.cpp b/test/SemaTemplate/nested-template.cpp
index 896eb72398..5ee2c99540 100644
--- a/test/SemaTemplate/nested-template.cpp
+++ b/test/SemaTemplate/nested-template.cpp
@@ -91,3 +91,13 @@ Y Outer<X>::Inner1<Y>::ReallyInner::value3 = Y();
template<typename X>
template<typename Y>
Y Outer<X>::Inner1<Y*>::ReallyInner::value4; // expected-error{{Outer<X>::Inner1<Y *>::ReallyInner::}}
+
+
+template<typename T>
+struct X0 { };
+
+template<typename T>
+struct X0<T*> {
+ template<typename U>
+ void f(U u = T()) { }
+};