[cfe-commits] r83469 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/CXX/temp/temp.decls/temp.class.spec/p6.cpp

Douglas Gregor dgregor at apple.com
Wed Oct 7 10:21:35 PDT 2009


Author: dgregor
Date: Wed Oct  7 12:21:34 2009
New Revision: 83469

URL: http://llvm.org/viewvc/llvm-project?rev=83469&view=rev
Log:
Class template partial specializations can be declared anywhere that
its definition may be defined, including in a class.

Also, put in an assertion when trying to instantiate a class template
partial specialization of a member template, which is not yet
implemented.


Added:
    cfe/trunk/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp
Modified:
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Oct  7 12:21:34 2009
@@ -2434,11 +2434,19 @@
     return true;
   }
   
+  // FIXME: For everything except class template partial specializations,
+  // complain if the explicit specialization/instantiation occurs at class 
+  // scope.
+
+  // C++ [temp.class.spec]p6:
+  //   A class template partial specialization may be declared or redeclared
+  //   in any namespace scope in which its definition may be defined (14.5.1 
+  //   and 14.5.2).  
   bool ComplainedAboutScope = false;
-  DeclContext *SpecializedContext
+  DeclContext *SpecializedContext 
     = Specialized->getDeclContext()->getEnclosingNamespaceContext();
+  DeclContext *DC = S.CurContext->getEnclosingNamespaceContext();
   if (TSK == TSK_ExplicitSpecialization) {
-    DeclContext *DC = S.CurContext->getEnclosingNamespaceContext();
     if ((!PrevDecl || 
          getTemplateSpecializationKind(PrevDecl) == TSK_Undeclared ||
          getTemplateSpecializationKind(PrevDecl) == TSK_ImplicitInstantiation)){
@@ -2468,8 +2476,8 @@
   // specializations of function templates, static data members, and member
   // functions, so we skip the check here for those kinds of entities.
   // FIXME: HandleDeclarator's diagnostics aren't quite as good, though.
-  // Should we refactor the check, so that it occurs later?
-  if (!ComplainedAboutScope && !S.CurContext->Encloses(SpecializedContext) &&
+  // Should we refactor that check, so that it occurs later?
+  if (!ComplainedAboutScope && !DC->Encloses(SpecializedContext) &&
       ((TSK == TSK_ExplicitSpecialization &&
         !(isa<FunctionTemplateDecl>(Specialized) || isa<VarDecl>(Specialized) ||
           isa<FunctionDecl>(Specialized))) || 

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Oct  7 12:21:34 2009
@@ -57,6 +57,8 @@
     ParmVarDecl *VisitParmVarDecl(ParmVarDecl *D);
     Decl *VisitOriginalParmVarDecl(OriginalParmVarDecl *D);
     Decl *VisitClassTemplateDecl(ClassTemplateDecl *D);
+    Decl *VisitClassTemplatePartialSpecializationDecl(
+                                    ClassTemplatePartialSpecializationDecl *D);
     Decl *VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
     Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
     Decl *VisitUnresolvedUsingDecl(UnresolvedUsingDecl *D);
@@ -401,6 +403,13 @@
 }
 
 Decl *
+TemplateDeclInstantiator::VisitClassTemplatePartialSpecializationDecl(
+                                   ClassTemplatePartialSpecializationDecl *D) {
+  assert(false &&"Partial specializations of member templates are unsupported");
+  return 0;
+}
+
+Decl *
 TemplateDeclInstantiator::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
   // FIXME: Dig out the out-of-line definition of this function template?
 

Added: cfe/trunk/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp?rev=83469&view=auto

==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp (added)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp Wed Oct  7 12:21:34 2009
@@ -0,0 +1,20 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+template<typename T>
+struct X0 {
+  template<typename U> struct Inner0 {
+    static const unsigned value = 0;
+  };
+  
+  template<typename U> struct Inner0<U*> { 
+    static const unsigned value = 1;
+  };
+};
+
+template<typename T> template<typename U>
+struct X0<T>::Inner0<const U*> {
+  static const unsigned value = 2;
+};
+
+// FIXME: Test instantiation of these partial specializations (once they are
+// implemented).





More information about the cfe-commits mailing list