diff --git a/include/fmt/format.h b/include/fmt/format.h index 4d414087..1710cf03 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -253,8 +253,13 @@ namespace detail { // undefined behavior (e.g. due to type aliasing). // Example: uint64_t d = bit_cast(2.718); template -inline auto bit_cast(const Source& source) -> Dest { +FMT_CONSTEXPR20 auto bit_cast(const Source& source) -> Dest { static_assert(sizeof(Dest) == sizeof(Source), "size mismatch"); +#ifdef __cpp_lib_bit_cast + if (is_constant_evaluated()) { + return std::bit_cast(source); + } +#endif Dest dest; std::memcpy(&dest, &source, sizeof(dest)); return dest;