Diagnose explicit instantiations and specializations that occur in class scope

llvm-svn: 83473
This commit is contained in:
Douglas Gregor 2009-10-07 17:30:37 +00:00
parent ae01f78a31
commit 40fb74484e
3 changed files with 15 additions and 4 deletions

View 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 "

View File

@ -2434,9 +2434,11 @@ static bool CheckTemplateSpecializationScope(Sema &S,
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

View 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 {