@@ -12777,8 +12777,9 @@ void Sema::ActOnFinishInlineFunctionDef(FunctionDecl *D) {
12777
12777
Consumer.HandleInlineFunctionDefinition(D);
12778
12778
}
12779
12779
12780
- static bool ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
12781
- const FunctionDecl*& PossibleZeroParamPrototype) {
12780
+ static bool
12781
+ ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
12782
+ const FunctionDecl *&PossiblePrototype) {
12782
12783
// Don't warn about invalid declarations.
12783
12784
if (FD->isInvalidDecl())
12784
12785
return false;
@@ -12815,21 +12816,18 @@ static bool ShouldWarnAboutMissingPrototype(const FunctionDecl *FD,
12815
12816
if (FD->isDeleted())
12816
12817
return false;
12817
12818
12818
- bool MissingPrototype = true;
12819
12819
for (const FunctionDecl *Prev = FD->getPreviousDecl();
12820
12820
Prev; Prev = Prev->getPreviousDecl()) {
12821
12821
// Ignore any declarations that occur in function or method
12822
12822
// scope, because they aren't visible from the header.
12823
12823
if (Prev->getLexicalDeclContext()->isFunctionOrMethod())
12824
12824
continue;
12825
12825
12826
- MissingPrototype = !Prev->getType()->isFunctionProtoType();
12827
- if (FD->getNumParams() == 0)
12828
- PossibleZeroParamPrototype = Prev;
12829
- break;
12826
+ PossiblePrototype = Prev;
12827
+ return Prev->getType()->isFunctionNoProtoType();
12830
12828
}
12831
12829
12832
- return MissingPrototype ;
12830
+ return true ;
12833
12831
}
12834
12832
12835
12833
void
@@ -13349,21 +13347,22 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
13349
13347
// prototype declaration. This warning is issued even if the
13350
13348
// definition itself provides a prototype. The aim is to detect
13351
13349
// global functions that fail to be declared in header files.
13352
- const FunctionDecl *PossibleZeroParamPrototype = nullptr;
13353
- if (ShouldWarnAboutMissingPrototype(FD, PossibleZeroParamPrototype )) {
13350
+ const FunctionDecl *PossiblePrototype = nullptr;
13351
+ if (ShouldWarnAboutMissingPrototype(FD, PossiblePrototype )) {
13354
13352
Diag(FD->getLocation(), diag::warn_missing_prototype) << FD;
13355
13353
13356
- if (PossibleZeroParamPrototype ) {
13354
+ if (PossiblePrototype ) {
13357
13355
// We found a declaration that is not a prototype,
13358
13356
// but that could be a zero-parameter prototype
13359
- if (TypeSourceInfo *TI =
13360
- PossibleZeroParamPrototype->getTypeSourceInfo()) {
13357
+ if (TypeSourceInfo *TI = PossiblePrototype->getTypeSourceInfo()) {
13361
13358
TypeLoc TL = TI->getTypeLoc();
13362
13359
if (FunctionNoProtoTypeLoc FTL = TL.getAs<FunctionNoProtoTypeLoc>())
13363
- Diag(PossibleZeroParamPrototype ->getLocation(),
13360
+ Diag(PossiblePrototype ->getLocation(),
13364
13361
diag::note_declaration_not_a_prototype)
13365
- << PossibleZeroParamPrototype
13366
- << FixItHint::CreateInsertion(FTL.getRParenLoc(), "void");
13362
+ << (FD->getNumParams() != 0)
13363
+ << (FD->getNumParams() == 0
13364
+ ? FixItHint::CreateInsertion(FTL.getRParenLoc(), "void")
13365
+ : FixItHint{});
13367
13366
}
13368
13367
}
13369
13368
0 commit comments