[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260112123722.GJ830755@noisy.programming.kicks-ass.net>
Date: Mon, 12 Jan 2026 13:37:22 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Al Viro <viro@...iv.linux.org.uk>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
Eric Dumazet <edumazet@...gle.com>, oe-kbuild-all@...ts.linux.dev,
linux-kernel@...r.kernel.org, Jakub Kicinski <kuba@...nel.org>,
Maciej Żenczykowski <maze@...gle.com>,
Will Deacon <will@...nel.org>,
"Paul E. McKenney" <paulmck@...nel.org>
Subject: Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar
On Sun, Jan 11, 2026 at 06:20:10PM +0000, Al Viro wrote:
> On Sat, Jan 10, 2026 at 10:35:48PM +0000, Al Viro wrote:
>
> > Folks involved in putting that cast in arch/alpha/include/asm/rwonce.h Cc'd...
>
> FWIW, there's a way to strip qualifiers from *any* non-array type.
> Look:
>
> void f(void)
> {
> const int x;
> x = 1; // an error
> typeof(((typeof(x)(*)(void))0)()) y;
> y = 2; // perfectly fine
> }
>
> The way it works is that qualifiers are stripped from return type when
> deriving a function type. That was spelled out only in C17; 6.7.6.3[5]
> | If, in the declaration "T D1", D1 has the form
> | D ( parameter-type-list )
> | or
> | D ( identifier-list[opt] )
> | and the type specified for ident in the declaration "T D" is
> | "derived-declarator-type-list T", then the type specified for ident
> | is "derived-declarator-type-list function returning the unqualified version
> | of T".
> but that "unqualified version of..." matched the common practice in
> earlier variants of standard; they stopped issuing TCs by that point
> (~2014), but both clang and gcc behave that way with any variant of
> standard.
>
> IOW, this
>
> #define unqual_non_array(T) __typeof__(((T(*)(void))0)())
>
> would do the right thing without that _Generic cascade and it'll work
> just fine for e.g. kuid_t. Using it for an array would trigger an error,
> array-returning functions being forbidden...
>
> Guys, do you have any problems with replacing __unqual_scalar_typeof()
> uses with that thing?
There is also __typeof_unqual__, but I do not know if that is now
supported by all compilers, if so that is the better option. If not,
your function return type thing is awesome.
Powered by blists - more mailing lists