From c36ed77ff0aac7b59eda7d2f6d968712be967d4d Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 2 Jan 2024 18:01:21 -0800 Subject: [PATCH] Get rid of addressof --- include/fmt/core.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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`.