From 206000a017be86811c83ceac1bd3d26adc966521 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 6 Jun 2021 06:51:37 -0700 Subject: [PATCH] Workaround pathological conversion (#2343) --- include/fmt/core.h | 2 +- test/format-test.cc | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 90fcef56..94d97859 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1539,7 +1539,7 @@ FMT_CONSTEXPR FMT_INLINE auto make_arg(const T& val) -> value { !std::is_same::value, "Cannot format an argument. To make type T formattable provide a " "formatter specialization: https://fmt.dev/latest/api.html#udt"); - return arg; + return {arg}; } template operator T() const { return T(); } +}; + +FMT_BEGIN_NAMESPACE +template <> struct formatter { + FMT_CONSTEXPR auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) { + return ctx.begin(); + } + + auto format(converible_to_anything, format_context& ctx) + -> decltype(ctx.out()) { + return format_to(ctx.out(), "foo"); + } +}; +FMT_END_NAMESPACE + +TEST(format_test, format_convertible_to_anything) { + EXPECT_EQ("foo", fmt::format("{}", converible_to_anything())); +} + class Answer {}; FMT_BEGIN_NAMESPACE