[PATCH 02/10] compiler.h: add is_const() as a replacement of __is_constexpr()
Linus Torvalds
torvalds at linux-foundation.org
Fri Dec 6 11:02:46 PST 2024
On Fri, 6 Dec 2024 at 10:52, Linus Torvalds
<torvalds at linux-foundation.org> wrote:
>
> This may be a case of "we just need to disable that incorrect compiler
> warning". Or does anybody see a workaround?
Hmm. The "== 0" thing does work, but as mentioned, that causes (more
valid, imho) warnings with pointers.
And it's not necessarily require that a pointer expression actually be
marked as a constant, as for the fact that these macros often get used
in various arbitrary contexts where things *might* be pointers, even
if "not constant" is a perfectly fine answer.
We do actually consciously use __builtin_constant_p() on pointers.
It's very convenient for format strings in particular, where
__builtin_constant_p() is a good test for a constant string, which
sometimes gets treated differently.
And in fact, dealing with NULL pointers statically might be worth it
too, so I do think it's worth keeping in mind.
Linus
More information about the linux-arm-kernel
mailing list