Reading thru https://github.com/isocpp/CppCoreGuidelines/issues/1517 I got the idea to get rid of the non-constexpr reinterpret_cast from my µC code (e.g. C could be a µC internal peripheral on address 0x100). Therefore I tried std::bit_cast-ing to a pointer type.
struct C {
inline static constexpr uintptr_t address = 0x100;
inline static constexpr C* ptr1 = std::bit_cast<C*>(address);
inline static /*constexpr*/ C* ptr2 = reinterpret_cast<C*>(address);
};
But according to the standard this is not possible because in this case std::bit_cast is not allowed to be constexpr (like reinterpret_cast).
Looks like this is still not possible? But why?
constexprbut the implementation wouldn't able to evaluate it to a constant.std::bit_castwith pointer types is exactly the same asreinterpret_cast, so the rules for why that isn't allowed in a constant expression are the same reasons why you can't usebit_cast.