diff --git a/include/fmt/base.h b/include/fmt/base.h index 23ef0c50..40637c56 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -1100,12 +1100,12 @@ struct use_format_as< T, bool_constant>::value>> : std::true_type {}; -template -using use_formatter = - bool_constant<(std::is_class::value || std::is_enum::value || - std::is_union::value) && - !has_to_string_view::value && !is_named_arg::value && - !use_format_as::value>; +template > +struct use_formatter + : bool_constant<(std::is_class::value || std::is_enum::value || + std::is_union::value) && + !has_to_string_view::value && !is_named_arg::value && + !use_format_as::value> {}; template constexpr auto has_const_formatter_impl(T*) @@ -1182,7 +1182,7 @@ template struct type_mapper { template ::value)> static auto map(const T& x) -> decltype(map(format_as(x))); - template >::value)> + template ::value)> static auto map(T&) -> conditional_t::value, T&, void>; template ::value)> @@ -2185,26 +2185,27 @@ template class value { template ::value)> value(const T& named_arg) : value(named_arg.value) {} - template >::value)> - FMT_CONSTEXPR20 FMT_INLINE value(T&& x) : value(x, custom_tag()) {} + template ::value)> + FMT_CONSTEXPR20 FMT_INLINE value(T& x) : value(x, custom_tag()) {} FMT_ALWAYS_INLINE value(const named_arg_info* args, size_t size) : named_args{args, size} {} private: template ::value)> - FMT_CONSTEXPR value(const T& x, custom_tag) { + FMT_CONSTEXPR value(T& x, custom_tag) { using value_type = remove_cvref_t; -#if defined(__cpp_if_constexpr) // T may overload operator& e.g. std::vector::reference in libc++. - if constexpr (std::is_same*>::value) - custom.value = const_cast(&x); -#endif - - custom.value = nullptr; - if (!is_constant_evaluated()) + if (!is_constant_evaluated()) { custom.value = const_cast(&reinterpret_cast(x)); + } else { + custom.value = nullptr; +#if defined(__cpp_if_constexpr) + if constexpr (std::is_same*>::value) + custom.value = const_cast(&x); +#endif + } custom.format = format_custom>; }