From: Johannes Berg <johannes@xxxxxxxxxxxxxxxx> Date: Wed, 18 Jan 2023 17:22:30 +0100 > On Wed, 2023-01-18 at 17:10 +0100, Alexander Lobakin wrote: >> >> Have you tried combining it with FIELD_PREP() using >> __builtin_choose_expr() + __builtin_is_constexpr() (or >> __builtin_constant_p() depending on which will satisfy the compiler)? >> I'm not saying it's 100% possible, but worth trying. >> > > I haven't tried it that way, but I tried rewriting FIELD_PREP() itself > to be constant-compatible, and as soon as the compiler saw > __builtin_constant_p() in the initializer it already complained that it > was non-constant... > > I didn't think of __builtin_choose_expr, but it doesn't work either > because it only promises that the unused expression is not *evaluated*, > not that it's not "looked at", so it still complains both ways (in the > constant case that you can't have ({ }) braced groups, and in the non- > constant case that the _CONST version is bad... Aaaah right. Seems like we can't avoid introducing a separate macro for that. I like the idea of your patch anyways! One note re __BF_CHECK_POW2(): can't we reuse is_power_of_2() anyhow? Foe example, by deriving the code of the latter into a macro and then using it in both? > > johannes Thanks, Olek