From 08ef0d0842b401ef928ff456df161d8bfacb0133 Mon Sep 17 00:00:00 2001 From: timsong-cpp Date: Sat, 20 May 2023 03:32:21 -1000 Subject: [PATCH] fix formatter (#3432) --- include/fmt/core.h | 2 +- test/format-test.cc | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 8848939f..6e658021 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -2694,7 +2694,7 @@ struct formatter \ struct formatter : formatter { \ template \ - auto format(const Type& val, FormatContext& ctx) const \ + auto format(Type const& val, FormatContext& ctx) const \ -> decltype(ctx.out()) { \ return formatter::format(static_cast(val), ctx); \ } \ diff --git a/test/format-test.cc b/test/format-test.cc index 6150e433..638bd143 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2245,3 +2245,19 @@ TEST(format_test, format_named_arg_with_locale) { } #endif // FMT_STATIC_THOUSANDS_SEPARATOR + +struct convertible_to_nonconst_cstring { + operator char*() const { + static char c[]="bar"; + return c; + } +}; + +FMT_BEGIN_NAMESPACE +template <> struct formatter : formatter { +}; +FMT_END_NAMESPACE + +TEST(format_test, formatter_nonconst_char) { + EXPECT_EQ(fmt::format("{}", convertible_to_nonconst_cstring()), "bar"); +}