Re: [PATCH 2/2] include/linux/typecheck.h: Zero initialize dummy variables
From: Al Viro
Date: Thu May 01 2025 - 22:05:48 EST
On Thu, May 01, 2025 at 06:24:49PM -0700, Nathan Chancellor wrote:
> > 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...
>From some digging around it looks like
* {} for compounds had been an extension for quite a while
* C++11 got it into standard, with semantics defined as "same
value you get for static-duration variables of that type without an
explicit initializer". For scalar types as well, with the same
semantics.
* On C side that happened (again, with scalar types allowed)
in 2022; N2912 is the first draft with that change already merged,
N2913 is the corresponding editor's report, saying that change in question
(N2900) got merged in January/February virtual meeting.
IOW, C23 has it, no previous versions do. For C17 this syntax
is an error, and AFAICS you need at least -std=c2x or -std=gnu2x to have
it acceptable.
We can make sparse accept it (either unconditionally or with sufficient
-std in arguments), but that won't do a damn thing for cc(1). Does
clang (any version) really accept it with -std=gnu11?