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:
parent
cca049ad2b
commit
e562a40871
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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}}
|
||||
};
|
Loading…
Reference in New Issue