[PATCH] D66919: Warn about zero-parameter K&R definitions in -Wstrict-prototypes

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 29 05:52:10 PDT 2019


aaron.ballman added a comment.

In D66919#1650174 <https://reviews.llvm.org/D66919#1650174>, @dexonsmith wrote:

> This could cause a lot of churn in existing projects (especially with `static void foo()`), without giving Clang any new information.  I'm wary of this.


Those projects likely aren't aware they're using prototypeless functions, which are trivial to call incorrectly. I suspect this diagnostic will find real bugs in code.

>> Zero-parameter K&R definitions specify that the function has no
>>  parameters, but they are still not prototypes, so calling the function
>>  with the wrong number of parameters is just a warning, not an error.
> 
> Why not just directly give an error for the problematic case?  We could carve out a `-W` flag (if it doesn't already exist) that warns if you incorrectly pass parameters to a function whose definition has no prototype, and then make it `-Werror`-by-default.

It's not incorrect to pass arguments to a function without a prototype, so that should not be an error. It is incorrect to pass the wrong number or types of arguments to a function without a prototype. It's not a bad idea to error in that circumstances, but there's no solution for `extern void foo()` where we don't see the actual definition.

If this turns out to be chatty in practice, we could put it under its own diagnostic flag (-Wstrict-prototype-no-params or something).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66919/new/

https://reviews.llvm.org/D66919





More information about the cfe-commits mailing list