@@ -2272,9 +2272,17 @@ static void checkNewAttributesAfterDef(Sema &S, Decl *New, const Decl *Old) {
22722272 const Attr *NewAttribute = NewAttributes[I];
22732273
22742274 if (isa<AliasAttr>(NewAttribute)) {
2275- if (FunctionDecl *FD = dyn_cast<FunctionDecl>(New))
2276- S.CheckForFunctionRedefinition(FD, cast<FunctionDecl>(Def));
2277- else {
2275+ if (FunctionDecl *FD = dyn_cast<FunctionDecl>(New)) {
2276+ Sema::SkipBodyInfo SkipBody;
2277+ S.CheckForFunctionRedefinition(FD, cast<FunctionDecl>(Def), &SkipBody);
2278+
2279+ // If we're skipping this definition, drop the "alias" attribute.
2280+ if (SkipBody.ShouldSkip) {
2281+ NewAttributes.erase(NewAttributes.begin() + I);
2282+ --E;
2283+ continue;
2284+ }
2285+ } else {
22782286 VarDecl *VD = cast<VarDecl>(New);
22792287 unsigned Diag = cast<VarDecl>(Def)->isThisDeclarationADefinition() ==
22802288 VarDecl::TentativeDefinition
@@ -10398,14 +10406,17 @@ void Sema::ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
1039810406 }
1039910407}
1040010408
10401- Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) {
10409+ Decl *
10410+ Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D,
10411+ MultiTemplateParamsArg TemplateParameterLists,
10412+ SkipBodyInfo *SkipBody) {
1040210413 assert(getCurFunctionDecl() == nullptr && "Function parsing confused");
1040310414 assert(D.isFunctionDeclarator() && "Not a function declarator!");
1040410415 Scope *ParentScope = FnBodyScope->getParent();
1040510416
1040610417 D.setFunctionDefinitionKind(FDK_Definition);
10407- Decl *DP = HandleDeclarator(ParentScope, D, MultiTemplateParamsArg() );
10408- return ActOnStartOfFunctionDef(FnBodyScope, DP);
10418+ Decl *DP = HandleDeclarator(ParentScope, D, TemplateParameterLists );
10419+ return ActOnStartOfFunctionDef(FnBodyScope, DP, SkipBody );
1040910420}
1041010421
1041110422void Sema::ActOnFinishInlineMethodDef(CXXMethodDecl *D) {
@@ -10469,7 +10480,8 @@ static bool ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
1046910480
1047010481void
1047110482Sema::CheckForFunctionRedefinition(FunctionDecl *FD,
10472- const FunctionDecl *EffectiveDefinition) {
10483+ const FunctionDecl *EffectiveDefinition,
10484+ SkipBodyInfo *SkipBody) {
1047310485 // Don't complain if we're in GNU89 mode and the previous definition
1047410486 // was an extern inline function.
1047510487 const FunctionDecl *Definition = EffectiveDefinition;
@@ -10481,17 +10493,20 @@ Sema::CheckForFunctionRedefinition(FunctionDecl *FD,
1048110493 return;
1048210494
1048310495 // If we don't have a visible definition of the function, and it's inline or
10484- // a template, it's OK to form another definition of it.
10485- //
10486- // FIXME: Should we skip the body of the function and use the old definition
10487- // in this case? That may be necessary for functions that return local types
10488- // through a deduced return type, or instantiate templates with local types.
10489- if (!hasVisibleDefinition(Definition) &&
10496+ // a template, skip the new definition.
10497+ if (SkipBody && !hasVisibleDefinition(Definition) &&
1049010498 (Definition->getFormalLinkage() == InternalLinkage ||
1049110499 Definition->isInlined() ||
1049210500 Definition->getDescribedFunctionTemplate() ||
10493- Definition->getNumTemplateParameterLists()))
10501+ Definition->getNumTemplateParameterLists())) {
10502+ SkipBody->ShouldSkip = true;
10503+ if (auto *TD = Definition->getDescribedFunctionTemplate())
10504+ makeMergedDefinitionVisible(TD, FD->getLocation());
10505+ else
10506+ makeMergedDefinitionVisible(const_cast<FunctionDecl*>(Definition),
10507+ FD->getLocation());
1049410508 return;
10509+ }
1049510510
1049610511 if (getLangOpts().GNUMode && Definition->isInlineSpecified() &&
1049710512 Definition->getStorageClass() == SC_Extern)
@@ -10552,7 +10567,8 @@ static void RebuildLambdaScopeInfo(CXXMethodDecl *CallOperator,
1055210567 }
1055310568}
1055410569
10555- Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D) {
10570+ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D,
10571+ SkipBodyInfo *SkipBody) {
1055610572 // Clear the last template instantiation error context.
1055710573 LastTemplateInstantiationErrorContext = ActiveTemplateInstantiation();
1055810574
@@ -10564,6 +10580,16 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D) {
1056410580 FD = FunTmpl->getTemplatedDecl();
1056510581 else
1056610582 FD = cast<FunctionDecl>(D);
10583+
10584+ // See if this is a redefinition.
10585+ if (!FD->isLateTemplateParsed()) {
10586+ CheckForFunctionRedefinition(FD, nullptr, SkipBody);
10587+
10588+ // If we're skipping the body, we're done. Don't enter the scope.
10589+ if (SkipBody && SkipBody->ShouldSkip)
10590+ return D;
10591+ }
10592+
1056710593 // If we are instantiating a generic lambda call operator, push
1056810594 // a LambdaScopeInfo onto the function stack. But use the information
1056910595 // that's already been calculated (ActOnLambdaExpr) to prime the current
@@ -10583,10 +10609,6 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D) {
1058310609 // Enter a new function scope
1058410610 PushFunctionScope();
1058510611
10586- // See if this is a redefinition.
10587- if (!FD->isLateTemplateParsed())
10588- CheckForFunctionRedefinition(FD);
10589-
1059010612 // Builtin functions cannot be defined.
1059110613 if (unsigned BuiltinID = FD->getBuiltinID()) {
1059210614 if (!Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID) &&
0 commit comments