Re: [PATCH 02/10] compiler.h: add is_const() as a replacement of __is_constexpr()
From: Martin Uecker
Date: Sat Dec 07 2024 - 10:10:47 EST
Am Samstag, dem 07.12.2024 um 22:50 +0900 schrieb Vincent Mailhol:
> On Sat. 7 Dec. 2024 à 22:19, Martin Uecker <muecker@xxxxxxx> wrote:
> >
...
>
> I was invited to WG14 this September. For now, I am only lurking. The
> thing I have in mind right now is to write a paper to allow the use of
> static_assert() in expressions (i.e. make it return 0 on success).
> That should be a relatively small change, but would bring a nice
> quality of life improvement.
>
> For context, look at this:
>
> https://lore.kernel.org/all/CAHk-=wjLSEcZ5LdW+3C+9rtjvNPHZT6zdk0POj67T5k2ZpDbgA@xxxxxxxxxxxxxx/T/#m1ba33a804b4041154b72a1d0333f90ec7204c461
What one can do is put it into a structure.
#define const_assert(x) \
(sizeof(struct { _Static_assert(x, ""); }))
but yeah, also a hack to work around a limitation of the standard
feature.
Martin