logoalt Hacker News

TuxSH04/24/20251 replyview on HN

No, you can't do that either: https://godbolt.org/z/vzdTMazx7 : error: '__builtin_bit_cast' is not a constant expression because 'char' is a pointer type

Here the `constexpr` keyword means the function might be called in a constant-evaluated context. f doesn't need to have all its statements be able to be evaluated in constexpr, only those which are actually used are. You need to explicitly instantiate a constexpr variable to test this.

cppreference is very clear* about this, regarding bit_cast: https://en.cppreference.com/w/cpp/numeric/bit_cast


Replies

lbhdc04/24/2025

Good catch. Its weird that it compiles without error as a consteval func.

show 1 reply