I convinced myself it should never happen, but can you add a negative C++ test as well?
(In C++ an empty parameter list is equivalent to one with 'void', but that would make the advance declaration a prototype.) Jordan On Dec 17, 2012, at 17:29 , Anders Carlsson <[email protected]> wrote: > Author: andersca > Date: Mon Dec 17 19:29:20 2012 > New Revision: 170399 > > URL: http://llvm.org/viewvc/llvm-project?rev=170399&view=rev > Log: > When warning about a missing prototype because a function declaration is > missing 'void', insert a fixit to add the void. > > Modified: > cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > cfe/trunk/lib/Sema/SemaDecl.cpp > cfe/trunk/test/Sema/warn-missing-prototypes.c > > Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=170399&r1=170398&r2=170399&view=diff > ============================================================================== > --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) > +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Dec 17 19:29:20 > 2012 > @@ -3176,6 +3176,8 @@ > def warn_missing_prototype : Warning< > "no previous prototype for function %0">, > InGroup<DiagGroup<"missing-prototypes">>, DefaultIgnore; > +def note_declaration_not_a_prototype : Note< > + "this declaration is not a prototype; add 'void' to make it a prototype > for a zero-parameter function">; > def warn_missing_variable_declarations : Warning< > "no previous extern declaration for non-static variable %0">, > InGroup<DiagGroup<"missing-variable-declarations">>, DefaultIgnore; > > Modified: cfe/trunk/lib/Sema/SemaDecl.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=170399&r1=170398&r2=170399&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) > +++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Dec 17 19:29:20 2012 > @@ -7762,7 +7762,8 @@ > return ActOnStartOfFunctionDef(FnBodyScope, DP); > } > > -static bool ShouldWarnAboutMissingPrototype(const FunctionDecl *FD) { > +static bool ShouldWarnAboutMissingPrototype(const FunctionDecl *FD, > + const FunctionDecl*& > PossibleZeroParamPrototype) { > // Don't warn about invalid declarations. > if (FD->isInvalidDecl()) > return false; > @@ -7804,6 +7805,8 @@ > continue; > > MissingPrototype = !Prev->getType()->isFunctionProtoType(); > + if (FD->getNumParams() == 0) > + PossibleZeroParamPrototype = Prev; > break; > } > > @@ -7869,8 +7872,22 @@ > // prototype declaration. This warning is issued even if the > // definition itself provides a prototype. The aim is to detect > // global functions that fail to be declared in header files. > - if (ShouldWarnAboutMissingPrototype(FD)) > + const FunctionDecl *PossibleZeroParamPrototype = 0; > + if (ShouldWarnAboutMissingPrototype(FD, PossibleZeroParamPrototype)) { > Diag(FD->getLocation(), diag::warn_missing_prototype) << FD; > + > + if (PossibleZeroParamPrototype) { > + // We found a declaration that is not a prototype, > + // but that could be a zero-parameter prototype > + TypeSourceInfo* TI = PossibleZeroParamPrototype->getTypeSourceInfo(); > + TypeLoc TL = TI->getTypeLoc(); > + if (FunctionNoProtoTypeLoc* FTL = > dyn_cast<FunctionNoProtoTypeLoc>(&TL)) > + Diag(PossibleZeroParamPrototype->getLocation(), > + diag::note_declaration_not_a_prototype) > + << PossibleZeroParamPrototype > + << FixItHint::CreateInsertion(FTL->getRParenLoc(), "void"); > + } > + } > > if (FnBodyScope) > PushDeclContext(FnBodyScope, FD); > > Modified: cfe/trunk/test/Sema/warn-missing-prototypes.c > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-missing-prototypes.c?rev=170399&r1=170398&r2=170399&view=diff > ============================================================================== > --- cfe/trunk/test/Sema/warn-missing-prototypes.c (original) > +++ cfe/trunk/test/Sema/warn-missing-prototypes.c Mon Dec 17 19:29:20 2012 > @@ -1,4 +1,5 @@ > -// RUN: %clang -Wmissing-prototypes -fsyntax-only -Xclang -verify %s > +// RUN: %clang_cc1 -fsyntax-only -Wdocumentation -Wmissing-prototypes > -verify %s > +// RUN: %clang_cc1 -fsyntax-only -Wdocumentation -Wmissing-prototypes > -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s > > int f(); > > @@ -35,3 +36,8 @@ > > // rdar://6759522 > int main(void) { return 0; } > + > +void not_a_prototype_test(); // expected-note{{this declaration is not a > prototype; add 'void' to make it a prototype for a zero-parameter function}} > +void not_a_prototype_test() { } // expected-warning{{no previous prototype > for function 'not_a_prototype_test'}} > + > +// CHECK: fix-it:"{{.*}}":{40:27-40:27}:"void" > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
