diff --git a/include/fmt/format.h b/include/fmt/format.h index 924e3700..5b7f6b52 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1847,8 +1847,13 @@ auto write(OutputIt out, const T& value) -> typename std::enable_if< mapped_type_constant>::value == type::custom_type, OutputIt>::type { - basic_format_context ctx(out, {}, {}); - return formatter().format(value, ctx); + using context_type = basic_format_context; + using formatter_type = + conditional_t::value, + typename context_type::template formatter_type, + fallback_formatter>; + context_type ctx(out, {}, {}); + return formatter_type().format(value, ctx); } // An argument visitor that formats the argument and writes it via the output diff --git a/test/ostream-test.cc b/test/ostream-test.cc index ce36b4cd..407b05a1 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -319,3 +319,7 @@ TEST(OStreamTest, CopyFmt) { TEST(OStreamTest, CompileTimeString) { EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), 42)); } + +TEST(OStreamTest, ToString) { + EXPECT_EQ("ABC", fmt::to_string(fmt_test::ABC())); +}