diff options
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 3 | ||||
-rw-r--r-- | lib/Sema/SemaTemplate.cpp | 10 | ||||
-rw-r--r-- | test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp | 6 |
3 files changed, 15 insertions, 4 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index c0a8651b36..6c8b631e39 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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 " diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 9d7dd0a056..6792b28d1c 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -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 diff --git a/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp b/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp index 7b50518605..77df60a25d 100644 --- a/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp +++ b/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp @@ -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 { |