[Bug c++/49171] [C++0x][constexpr] Constant expressions support reinterpret_cast
comexk at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sun Feb 9 23:06:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49171
--- Comment #24 from comexk at gmail dot com ---
> All that's needed for that is an extension to provide a compile-time constant value to a pointer, not to allow arbitrary reinterpret_casts in constexpr.
Well, there aren't that many things that reinterpret_cast can do. Casting
pointers to different pointer types would be useful, but using such pointers is
normally undefined behavior anyway. The exception is accessing byte
representations using `char *` pointers. Supporting that in constexpr context
*would* be a major feature, but it doesn't need to be allowed just because the
cast itself is allowed.
On the other hand, C++20 is adding an alternate way to manipulate byte
representations in constexpr context, std::bit_cast. (It's non-constexpr when
the types involved contain unions or pointers, so it can't be used directly in
place of reinterpret_cast.) Most of the work that would be needed to support
access-through-`char *` as an extension needs to be done anyway for
std::bit_cast; on the other hand, its existence reduces the need for an
extension.
Regardless, it would be nice to lift the pointer restriction on std::bit_cast
as an extension.
More information about the Gcc-bugs
mailing list