diff options
author | Francois Pichet <pichet2000@gmail.com> | 2011-05-14 17:46:46 +0000 |
---|---|---|
committer | Francois Pichet <pichet2000@gmail.com> | 2011-05-14 17:46:46 +0000 |
commit | 1fa8028d9ff5de64f8b9d55731ca83a2d3423a77 (patch) | |
tree | 266798745da1de6aa4ce53152d27d1a443c34c26 | |
parent | 1804174e1591bf59118f317775b48edd0382c3f0 (diff) |
In Microsoft mode, allow template function explicit specialization at class scope.
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
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 3 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 8 | ||||
-rw-r--r-- | lib/Sema/SemaTemplate.cpp | 9 | ||||
-rw-r--r-- | test/SemaCXX/MicrosoftExtensions.cpp | 7 |
4 files changed, 22 insertions, 5 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index ea1ef56010..ea82cf80ed 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1775,6 +1775,9 @@ def err_template_spec_decl_function_scope : Error< "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< diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 58b807fb2a..25d23584b8 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1685,10 +1685,14 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { 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. diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index c31ed01737..9b14f63301 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -4401,9 +4401,12 @@ static bool CheckTemplateSpecializationScope(Sema &S, } 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: diff --git a/test/SemaCXX/MicrosoftExtensions.cpp b/test/SemaCXX/MicrosoftExtensions.cpp index 88e3922670..e1c64b1ac8 100644 --- a/test/SemaCXX/MicrosoftExtensions.cpp +++ b/test/SemaCXX/MicrosoftExtensions.cpp @@ -197,3 +197,10 @@ void pointer_to_integral_type_conv(char* ptr) { 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}} +}; |