[PATCH] D122895: [C89/C2x] Improve diagnostics around strict prototypes in C
Eli Friedman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 12 15:58:22 PDT 2022
efriedma added inline comments.
================
Comment at: clang/test/Sema/warn-strict-prototypes.m:20
+ // know it's a block when diagnosing.
+ void (^block2)(void) = ^void() { // expected-warning {{a function declaration without a prototype is deprecated in all versions of C}}
};
----------------
dexonsmith wrote:
> dexonsmith wrote:
> > This is a definition, so the compiler knows that there are no parameters. Why would we warn here? Reading https://discourse.llvm.org/t/rfc-enabling-wstrict-prototypes-by-default-in-c/60521/18 it looks to me like an example of what @rnk was referring to, about churning code to add `(void)` and then return back to `()` later.
> >
> > (cc: @steven_wu and @rjmccall as well)
> Specifically, `^void() { /* anything */}` is the definition of a block with zero parameters. Maybe pedantically it's lacking a prototype, but the compiler knows (since this is the definition) how many parameters there are.
>
> (Same goes for `void() { /* anything */ }` at global scope; is that triggering `-Wstrict-prototypes` now too?)
To be clear, you're asking specifically about the following two cases where the behavior with -Wstrict-prototypes changed, right? I don't think this was really discussed in the RFC.
```
// Block
void (^f1)(void) = ^(){};
// Function definition
void f(void);
void f(){}
```
Note that the behavior of the following did not change:
```
void (^f1)(void) = ^{}; // no warning
void f2(){} // warning since clang 11.
```
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