Fix for PR47544. Clang is crashing after generating the right

diagnostic for a re-declaration of a friend method.d
https://reviews.llvm.org/D88112
This commit is contained in:
Zahira Ammarguellat 2020-10-27 05:51:02 -07:00
parent cca049ad2b
commit e562a40871
2 changed files with 25 additions and 7 deletions

View File

@ -405,14 +405,21 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) {
ConsumeAnyToken();
} else if (HasUnparsed) {
assert(Param->hasInheritedDefaultArg());
FunctionDecl *Old = cast<FunctionDecl>(LM.Method)->getPreviousDecl();
ParmVarDecl *OldParam = Old->getParamDecl(I);
assert (!OldParam->hasUnparsedDefaultArg());
if (OldParam->hasUninstantiatedDefaultArg())
Param->setUninstantiatedDefaultArg(
OldParam->getUninstantiatedDefaultArg());
const FunctionDecl *Old;
if (const auto *FunTmpl = dyn_cast<FunctionTemplateDecl>(LM.Method))
Old =
cast<FunctionDecl>(FunTmpl->getTemplatedDecl())->getPreviousDecl();
else
Param->setDefaultArg(OldParam->getInit());
Old = cast<FunctionDecl>(LM.Method)->getPreviousDecl();
if (Old) {
ParmVarDecl *OldParam = const_cast<ParmVarDecl*>(Old->getParamDecl(I));
assert(!OldParam->hasUnparsedDefaultArg());
if (OldParam->hasUninstantiatedDefaultArg())
Param->setUninstantiatedDefaultArg(
OldParam->getUninstantiatedDefaultArg());
else
Param->setDefaultArg(OldParam->getInit());
}
}
}

View File

@ -0,0 +1,11 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
class test1 {
template <typename> friend int bar(bool = true) {} // expected-note {{previous declaration is here}}
template <typename> friend int bar(bool); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
};
class test2 {
friend int bar(bool = true) {} // expected-note {{previous declaration is here}}
friend int bar(bool); // expected-error{{friend declaration specifying a default argument must be the only declaration}}
};