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 (*).
I thought the same thing but I tend to trust people who are smarter than I am :)
How long has that been valid? Because this is certainly new to the kernel, and sparse does complain about this initializer.
As you noted, brace initialization for scalars appears to always be valid (at least in my testing) but as Al points out, empty braces for scalars is only supported in GCC 13+ and Clang 17+ (I think [1] was the clang commit), so that is not going to fly...
So honestly, this will just cause endless sparse warnings instead. I think disabling this warning for now is likely the right thing to do.
but '= {0}' appears to work: https://godbolt.org/z/x7eae5vex
If using that instead upsets sparse still, then I can just abandon this change and update the other patch to disable -Wdefault-const-init-unsafe altogether (rather than just the field variant) but it seems like you were not entirely opposed to this even in spite of sparse not supporting it. If that does work, I will send a v2 tomorrow.
[1]: https://github.com/llvm/llvm-project/commit/5d8aaad4452f60ba8902e921d9bed606...
Cheers, Nathan