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

From: David Laight
Date: Thu Jul 25 2024 - 05:13:52 EST


From: Arnd Bergmann
> Sent: 24 July 2024 18:32
>
> 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.

Well it would be -rc1 (or maybe -rc2).

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

The safer option would be to add __if_constexpr() but leave the
change to __is_constexpr() for 'next'.

David

>
> Arnd

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)