[cfe-commits] r81407 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/SemaTemplate/nested-template.cpp

Douglas Gregor dgregor at apple.com
Wed Sep 9 17:13:04 PDT 2009


Author: dgregor
Date: Wed Sep  9 19:12:48 2009
New Revision: 81407

URL: http://llvm.org/viewvc/llvm-project?rev=81407&view=rev
Log:
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>.

Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/SemaTemplate/nested-template.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Sep  9 19:12:48 2009
@@ -1858,11 +1858,19 @@
 }
 
 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) {

Modified: cfe/trunk/test/SemaTemplate/nested-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/nested-template.cpp?rev=81407&r1=81406&r2=81407&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/nested-template.cpp (original)
+++ cfe/trunk/test/SemaTemplate/nested-template.cpp Wed Sep  9 19:12:48 2009
@@ -91,3 +91,13 @@
 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()) { }
+};





More information about the cfe-commits mailing list