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.

llvm-svn: 225511
This commit is contained in:
David Majnemer 2015-01-09 07:36:13 +00:00
parent b68fa3b576
commit aa30dd7497
2 changed files with 13 additions and 2 deletions

View File

@ -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<CXXMethodDecl>(NewFD);
isDependentClassScopeExplicitSpecialization = true;
Diag(NewFD->getLocation(), getLangOpts().MicrosoftExt ?
diag::ext_function_specialization_in_class :
diag::err_function_specialization_in_class)

View File

@ -199,5 +199,11 @@ namespace PR22040 {
template <typename>
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 <typename>
void ::f(); // expected-error{{cannot have a qualified name}}
virtual void f1() = 0;
};