Re: [PATCH 3/7] compiler.h: Add __if_constexpr(expr, if_const, if_not_const)

From: Arnd Bergmann
Date: Wed Jul 24 2024 - 13:33:33 EST


On Wed, Jul 24, 2024, at 16:29, David Laight wrote:

> +#define __if_constexpr(expr, if_const, if_not_const) \
> + _Generic(0 ? ((void *)((long)(expr) * 0l)) : (char *)0, \
> + char *: (if_const), \
> + void *: (if_not_const))
> +
> -#define __is_constexpr(x) \
> - (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
> +#define __is_constexpr(expr) __if_constexpr((expr), 1, 0)

I don't immediately see anything wrong with this, but I'm
still scared of any change to it, especially if this is
meant to go straight into mainline.

Would it be possible to do patch 4/7 without the new
__if_constexpr() and instead still using __builtin_choose_expr()?

Arnd