std::bit_cast to pointer type not useable in constexpr context

328 views Asked by At

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?

0

There are 0 answers