[PATCH] D122895: [C89/C2x] Improve diagnostics around strict prototypes in C

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 12 09:10:24 PDT 2022


aaron.ballman added inline comments.


================
Comment at: clang/test/CodeGen/2009-06-01-addrofknr.c:8
 
-static int func(f)
+static int func(f) // expected-warning {{this function declaration without a prototype is deprecated in all versions of C and changes behavior in C2x}}
   void *f;
----------------
aaron.ballman wrote:
> jyknight wrote:
> > aaron.ballman wrote:
> > > aaron.ballman wrote:
> > > > jyknight wrote:
> > > > > This message seems vaguer than necessary, since we know _for sure_ this is invalid.
> > > > > 
> > > > > Can we say something like: "K&R-style function definitions are deprecated in all versions of C and not supported in C2x"?
> > > > I'd like to avoid using K&R in the diagnostic text (we're inconsistent about K&R vs prototype, etc already, but I'd like to see us excise `K&R` from diagnostics because it's not particularly descriptive to anyone younger than about 40. :-D
> > > > 
> > > > How about: `function declarations without a prototype are deprecated in all versions of C and not supported in C2x` ?
> > > I went with `a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x`, let me know if you think it needs further adjusting. I also reworded the other diagnostics to sound similar.
> > I do agree with you that "K&R" is perhaps not the best name either...
> > 
> > But I think this warning message may still be confusing to users. A typical C user I think will be surprised to see a warning about a "declaration" pointing to a definition -- even though that is technically accurate. Especially when we're complaining concretely about the weird old definition syntax, it would be better to say "definition".
> > 
> > It looks like the most common name for this is "old-style function definition" -- both GCC and MSVC use that name, and clang also did, before. (Hmmm. And GCC actually seems to place this particular warning under the off-by-default -Wold-style-definition flag -- which clang doesn't implement.) I don't know that "old-style" is a great description either, but "old-style function definition" definitely seems more understandable than "function declaration without a prototype" when talking about a K&R-style separated-arguments-types definition.
> > But I think this warning message may still be confusing to users. A typical C user I think will be surprised to see a warning about a "declaration" pointing to a definition -- even though that is technically accurate. Especially when we're complaining concretely about the weird old definition syntax, it would be better to say "definition".
> 
> I can look into making it say "definition" when written on a definition, but this feels like it's starting to split awfully fine hairs to me, so if it turns out to add more code than I think it's worth, I may stick with "declaration" because it's still correct and I don't think the confusion should impede a user's ability to fix the bug *too much*.
Yup, this turned out to be hard enough to not be worth it IMO. The issue is that when merging function declarations, we don't know whether the function we want to diagnose is a definition or not (we've not yet started parsing its body, we've just finished with its declarator).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122895



More information about the cfe-commits mailing list