On Thu, May 01, 2025 at 04:28:25PM -0700, Linus Torvalds wrote:
On Thu, 1 May 2025 at 16:00, Nathan Chancellor nathan@kernel.org wrote:
+({ type __dummy = {}; \
typeof(x) __dummy2 = {}; \
I'm actually surprised that this doesn't cause warnings in itself.
The types in question are not necessarily compound types, and can be simple types like 'int'.
The fact that you can write
int x = {};
without the compiler screaming bloody murder about that insanity blows my mind, but it does seem to be valid C (*).
How long has that been valid? Because this is certainly new to the kernel, and sparse does complain about this initializer.
So honestly, this will just cause endless sparse warnings instead. I think disabling this warning for now is likely the right thing to do.
Linus
(*) Yes, the empty initializer is new in C23, but we've used that in the kernel for non-scalar objects for a long time.
For scalars it had been flat-out invalid all along - doesn't even need -Wpedantic for gcc to reject that. I hadn't checked C23, but older variants all fail on that.
We can force sparse to accept that thing, but I rather wonder if it's a good idea. Both gcc 12 and clang 14 give hard error with -std=gnu11; do we really want to bump the minimal versions that much?