]> granicus.if.org Git - clang/commitdiff
Diagnose explicit instantiations and specializations that occur in class scope
authorDouglas Gregor <dgregor@apple.com>
Wed, 7 Oct 2009 17:30:37 +0000 (17:30 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 7 Oct 2009 17:30:37 +0000 (17:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83473 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaTemplate.cpp
test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp

index c0a8651b36acd873ae3724d8f8b2bb3e8f4b0ef8..6c8b631e391fcdc61d71d8bf77d1a4a6542fedde 100644 (file)
@@ -927,6 +927,9 @@ def note_specialized_entity : Note<
 def err_template_spec_decl_function_scope : Error<
   "explicit %select{<error>|<error>|specialization|instantiation|"
   "instantiation}0 of %1 in function scope">;
+def err_template_spec_decl_class_scope : Error<
+  "explicit %select{<error>|<error>|specialization|instantiation|"
+  "instantiation}0 of %1 in class scope">;
 def err_template_spec_decl_out_of_scope_global : Error<
   "%select{class template|class template partial|function template|member "
   "function|static data member|member class}0 specialization of %1 must "
index 9d7dd0a056944772206a71b88a1930969c835db0..6792b28d1c830229052f9c858e2b13ab19300fb5 100644 (file)
@@ -2433,11 +2433,13 @@ static bool CheckTemplateSpecializationScope(Sema &S,
       << TSK << Specialized;
     return true;
   }
-  
-  // FIXME: For everything except class template partial specializations,
-  // complain if the explicit specialization/instantiation occurs at class 
-  // scope.
 
+  if (S.CurContext->isRecord() && !IsPartialSpecialization) {
+    S.Diag(Loc, diag::err_template_spec_decl_class_scope)
+      << TSK << Specialized;
+    return true;
+  }
+  
   // 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 
index 7b505186055041943f8130e5a31e703f41078521..77df60a25d3447268921b47c57bd55f1874f36ca 100644 (file)
@@ -38,6 +38,12 @@ namespace N1 {
 
 template<> void N0::f0(double) { } // expected-error{{originally be declared}}
 
+struct X1 {
+  template<typename T> void f(T);
+  
+  template<> void f(int); // expected-error{{in class scope}}
+};
+
 //     -- class template
 namespace N0 {