Fix detection of unformattable pointers

This commit is contained in:
Victor Zverovich 2022-04-12 06:45:46 -07:00
parent fc429d18b6
commit 395cf0f03e
2 changed files with 13 additions and 0 deletions

View File

@ -1478,6 +1478,7 @@ template <typename Context> struct arg_mapper {
template <typename T, typename U = remove_cvref_t<T>,
FMT_ENABLE_IF(!is_string<U>::value && !is_char<U>::value &&
!std::is_array<U>::value &&
!std::is_pointer<U>::value &&
!has_format_as<U>::value &&
(has_formatter<U, Context>::value ||
has_fallback_formatter<U, char_type>::value))>

View File

@ -679,6 +679,7 @@ TEST(format_test, constexpr_parse_format_string) {
#endif // FMT_USE_CONSTEXPR
struct enabled_formatter {};
struct enabled_ptr_formatter {};
struct disabled_formatter {};
struct disabled_formatter_convertible {
operator int() const { return 42; }
@ -693,6 +694,16 @@ template <> struct formatter<enabled_formatter> {
return ctx.out();
}
};
template <> struct formatter<enabled_ptr_formatter*> {
auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) {
return ctx.begin();
}
auto format(enabled_ptr_formatter*, format_context& ctx)
-> decltype(ctx.out()) {
return ctx.out();
}
};
FMT_END_NAMESPACE
TEST(core_test, has_formatter) {
@ -785,6 +796,7 @@ TEST(core_test, is_formattable) {
static_assert(!fmt::is_formattable<fmt::basic_string_view<wchar_t>>::value,
"");
static_assert(fmt::is_formattable<enabled_formatter>::value, "");
static_assert(!fmt::is_formattable<enabled_ptr_formatter*>::value, "");
static_assert(!fmt::is_formattable<disabled_formatter>::value, "");
static_assert(fmt::is_formattable<disabled_formatter_convertible>::value, "");