[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
Fri Feb 14 10:12:41 PST 2020


aaron.ballman added inline comments.


================
Comment at: clang/test/Sema/warn-strict-prototypes.c:11
+// function definition with 0 params, no prototype.
+void foo1() {} // expected-warning {{this old-style function definition is not preceded by a prototype}}
+// function definition with 0 params, prototype.
----------------
aaronpuchert wrote:
> aaronpuchert wrote:
> > aaron.ballman wrote:
> > > I'd like a few more test cases:
> > > ```
> > > // Test that a non-prototyped definition with no preceding prototype whines about lacking a preceding prototype
> > > void fooN() {} // expected-warning {{this old-style function definition is not preceded by a prototype}}
> > > 
> > > // Test that an existing declaration with no prototype still warns that a corresponding definition with a type list is still not preceded by a prototype.
> > > void fooN1(); // expected-warning {{this function declaration is not a prototype}}
> > > void fooN1(void) {} // expected-warning {{this old-style function definition is not preceded by a prototype}}
> > > ```
> > I guess we want the warning only on the declaration of `fooN1`, not the definition? Because that's not an old-style function definition.
> Yeah, I'm not sure about `fooN1`. We can't emit the warning on the definition (and I think we also don't need to, as we diagnose that before), and the warning on the declaration is kind of tested already. (Note that there is also `-Wmissing-prototypes`.)
> 
> But `fooN` definitely makes sense, I'll add that.
I think you're right about the `fooN1` definition not needing a warning -- I was thinking we wanted to warn because there was no preceding prototype, but it's not an old-style declaration at that definition. You can ignore that suggestion.


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