Re: include/net/sock.h:2100:16: sparse: sparse: cast to non-scalar

From: Al Viro

Date: Sun Jan 11 2026 - 13:18:49 EST


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?

As in,#ifndef __smp_load_acquire
#define __smp_load_acquire(p) \
({ \
unqual_non_array(__typeof__(*p)) ___p1 = READ_ONCE(*p); \
...

Objections? IMO it's more palatable than current __unqual_scalar_typeof()...