@@ -14657,6 +14657,21 @@ void Sema::ActOnFinishInlineFunctionDef(FunctionDecl *D) {
14657
14657
Consumer.HandleInlineFunctionDefinition(D);
14658
14658
}
14659
14659
14660
+ static bool FindPossiblePrototype(const FunctionDecl *FD,
14661
+ const FunctionDecl *&PossiblePrototype) {
14662
+ for (const FunctionDecl *Prev = FD->getPreviousDecl(); Prev;
14663
+ Prev = Prev->getPreviousDecl()) {
14664
+ // Ignore any declarations that occur in function or method
14665
+ // scope, because they aren't visible from the header.
14666
+ if (Prev->getLexicalDeclContext()->isFunctionOrMethod())
14667
+ continue;
14668
+
14669
+ PossiblePrototype = Prev;
14670
+ return Prev->getType()->isFunctionProtoType();
14671
+ }
14672
+ return false;
14673
+ }
14674
+
14660
14675
static bool
14661
14676
ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
14662
14677
const FunctionDecl *&PossiblePrototype) {
@@ -14703,16 +14718,9 @@ ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
14703
14718
if (!FD->isExternallyVisible())
14704
14719
return false;
14705
14720
14706
- for (const FunctionDecl *Prev = FD->getPreviousDecl();
14707
- Prev; Prev = Prev->getPreviousDecl()) {
14708
- // Ignore any declarations that occur in function or method
14709
- // scope, because they aren't visible from the header.
14710
- if (Prev->getLexicalDeclContext()->isFunctionOrMethod())
14711
- continue;
14712
-
14713
- PossiblePrototype = Prev;
14714
- return Prev->getType()->isFunctionNoProtoType();
14715
- }
14721
+ // If we were able to find a potential prototype, don't warn.
14722
+ if (FindPossiblePrototype(FD, PossiblePrototype))
14723
+ return false;
14716
14724
14717
14725
return true;
14718
14726
}
@@ -15280,6 +15288,12 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
15280
15288
}
15281
15289
}
15282
15290
15291
+ // We might not have found a prototype because we didn't wish to warn on
15292
+ // the lack of a missing prototype. Try again without the checks for
15293
+ // whether we want to warn on the missing prototype.
15294
+ if (!PossiblePrototype)
15295
+ (void)FindPossiblePrototype(FD, PossiblePrototype);
15296
+
15283
15297
// If the function being defined does not have a prototype, then we may
15284
15298
// need to diagnose it as changing behavior in C2x because we now know
15285
15299
// whether the function accepts arguments or not. This only handles the
0 commit comments