diff --git a/include/fmt/core.h b/include/fmt/core.h index fa82fb99..e5b1e4f0 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -13,7 +13,6 @@ #include // std::strlen #include // std::back_insert_iterator #include // std::numeric_limits -#include // std::addressof #include #include @@ -1306,7 +1305,12 @@ template class value { template FMT_CONSTEXPR20 FMT_INLINE value(T& val) { using value_type = remove_const_t; - custom.value = const_cast(std::addressof(val)); +#ifdef __cpp_if_constexpr + if constexpr (std::is_same::value) + custom.value = const_cast(&val); +#endif + if (!is_constant_evaluated()) + custom.value = const_cast(&reinterpret_cast(val)); // Get the formatter type through the context to allow different contexts // have different extension points, e.g. `formatter` for `format` and // `printf_formatter` for `printf`.