Re: [PATCH 2/2] include/linux/typecheck.h: Zero initialize dummy variables

From: Linus Torvalds
Date: Thu May 01 2025 - 19:28:53 EST


On Thu, 1 May 2025 at 16:00, Nathan Chancellor <nathan@xxxxxxxxxx> 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.