From: David Majnemer Date: Fri, 9 Jan 2015 07:36:13 +0000 (+0000) Subject: Sema: RecordDecl shouldn't have a FunctionDecl as a Decl X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a2f75da3f0d6d316bd8a494045044b10fc982bc2;p=clang Sema: RecordDecl shouldn't have a FunctionDecl as a Decl RecordDecls should have things like CXXMethodDecls or FriendDecls as a decl but not things like FunctionDecls. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225511 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 1e20121b37..970b2ecd72 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -6712,6 +6712,11 @@ static FunctionDecl* CreateNewFunctionDecl(Sema &SemaRef, Declarator &D, IsVirtualOkay = !Ret->isStatic(); return Ret; } else { + bool isFriend = + SemaRef.getLangOpts().CPlusPlus && D.getDeclSpec().isFriendSpecified(); + if (!isFriend && SemaRef.CurContext->isRecord()) + return nullptr; + // Determine whether the function was written with a // prototype. This true when: // - we're in C++ (where every function has a prototype), @@ -7482,7 +7487,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, } else if (isFunctionTemplateSpecialization) { if (CurContext->isDependentContext() && CurContext->isRecord() && !isFriend) { - isDependentClassScopeExplicitSpecialization = isa(NewFD); + isDependentClassScopeExplicitSpecialization = true; 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 c2d4704bc0..961884417b 100644 --- a/test/SemaTemplate/instantiate-method.cpp +++ b/test/SemaTemplate/instantiate-method.cpp @@ -199,5 +199,11 @@ namespace PR22040 { template struct SpecializationOfGlobalFnInClassScope { template <> - void ::Fn(); // expected-error{{cannot have a qualified name}} expected-error{{cannot specialize a function}} + void ::Fn(); // expected-error{{cannot have a qualified name}} +}; + +class AbstractClassWithGlobalFn { + template + void ::f(); // expected-error{{cannot have a qualified name}} + virtual void f1() = 0; };