From ea6cc726d11365a23ac85d1c3d5884809895843e Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Fri, 9 Jan 2015 06:10:21 +0000 Subject: [PATCH] Sema: Don't crash when specializing a global scope function in a class We assumed that class-scope specializations would result in a CXXMethodDecl for that class. However, globally qualified functions will result in normal FunctionDecls. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225508 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 2 +- test/SemaTemplate/instantiate-method.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 8a5047592a..1e20121b37 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -7482,7 +7482,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, } else if (isFunctionTemplateSpecialization) { if (CurContext->isDependentContext() && CurContext->isRecord() && !isFriend) { - isDependentClassScopeExplicitSpecialization = true; + isDependentClassScopeExplicitSpecialization = isa(NewFD); Diag(NewFD->getLocation(), getLangOpts().MicrosoftExt ? diag::ext_function_specialization_in_class : diag::err_function_specialization_in_class) diff --git a/test/SemaTemplate/instantiate-method.cpp b/test/SemaTemplate/instantiate-method.cpp index 4cc40af7e1..c2d4704bc0 100644 --- a/test/SemaTemplate/instantiate-method.cpp +++ b/test/SemaTemplate/instantiate-method.cpp @@ -195,3 +195,9 @@ namespace PR22040 { Foobar::bazqux(3); // expected-error{{no member named 'bazqux' in }} } } + +template +struct SpecializationOfGlobalFnInClassScope { + template <> + void ::Fn(); // expected-error{{cannot have a qualified name}} expected-error{{cannot specialize a function}} +}; -- 2.50.1