From 395cf0f03ecaa35c24faaaca42d481e316f00422 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 12 Apr 2022 06:45:46 -0700 Subject: [PATCH] Fix detection of unformattable pointers --- include/fmt/core.h | 1 + test/core-test.cc | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/fmt/core.h b/include/fmt/core.h index d8aa4deb..36c92f66 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1478,6 +1478,7 @@ template struct arg_mapper { template , FMT_ENABLE_IF(!is_string::value && !is_char::value && !std::is_array::value && + !std::is_pointer::value && !has_format_as::value && (has_formatter::value || has_fallback_formatter::value))> diff --git a/test/core-test.cc b/test/core-test.cc index a040d241..8692c76b 100644 --- a/test/core-test.cc +++ b/test/core-test.cc @@ -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 { return ctx.out(); } }; + +template <> struct 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>::value, ""); static_assert(fmt::is_formattable::value, ""); + static_assert(!fmt::is_formattable::value, ""); static_assert(!fmt::is_formattable::value, ""); static_assert(fmt::is_formattable::value, "");