Necessary to parse MFC and MSVC standard lib code.
Example:
struct X {
template<class T> void f(T) { }
template<> void f(int) { }
}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131347
91177308-0d34-0410-b5e6-
96231b3b80d8
"explicit specialization of %0 in function scope">;
def err_template_spec_decl_class_scope : Error<
"explicit specialization of %0 in class scope">;
+def war_template_spec_decl_class_scope : ExtWarn<
+ "Allowing explicit specialization of %0 in class scope is a Microsoft "
+ "extension">, InGroup<Microsoft>;
def err_template_spec_decl_friend : Error<
"cannot declare an explicit specialization in a friend">;
def err_template_spec_decl_out_of_scope_global : Error<
if (OldMethod && NewMethod) {
// Preserve triviality.
NewMethod->setTrivial(OldMethod->isTrivial());
-
+
+ // MSVC allows explicit template specialization at class scope.
+ bool IsMSExplicitSpecialization = getLangOptions().Microsoft &&
+ NewMethod->isFunctionTemplateSpecialization();
bool isFriend = NewMethod->getFriendObjectKind();
- if (!isFriend && NewMethod->getLexicalDeclContext()->isRecord()) {
+ if (!isFriend && NewMethod->getLexicalDeclContext()->isRecord() &&
+ !IsMSExplicitSpecialization) {
// -- Member function declarations with the same name and the
// same parameter types cannot be overloaded if any of them
// is a static member function declaration.
}
if (S.CurContext->isRecord() && !IsPartialSpecialization) {
- S.Diag(Loc, diag::err_template_spec_decl_class_scope)
- << Specialized;
- return true;
+ if (S.getLangOptions().Microsoft)
+ S.Diag(Loc, diag::war_template_spec_decl_class_scope) << Specialized;
+ else {
+ S.Diag(Loc, diag::err_template_spec_decl_class_scope) << Specialized;
+ return true;
+ }
}
// C++ [temp.class.spec]p6:
ch = (char)ptr;
sh = (short)ptr;
}
+
+
+struct X1 {
+ template<typename T> void f(T);
+
+ template<> void f(int) { } // expected-warning{{Allowing explicit specialization of 'f' in class scope is a Microsoft extension}}
+};