diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 29226350..b4a1c14b 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -524,9 +524,9 @@ FMT_CONSTEXPR20 auto formatted_size(const S& fmt, const Args&... args) template ::value)> void print(std::FILE* f, const S& fmt, const Args&... args) { - memory_buffer buffer; - fmt::format_to(std::back_inserter(buffer), fmt, args...); - detail::print(f, {buffer.data(), buffer.size()}); + auto buf = memory_buffer(); + fmt::format_to(appender(buf), fmt, args...); + detail::print(f, {buf.data(), buf.size()}); } template struct formatter : formatter { + auto format(std_context_test, format_context& ctx) const + -> decltype(ctx.out()) { + return ctx.out(); + } +}; +FMT_END_NAMESPACE + TEST(compile_test, print) { EXPECT_WRITE(stdout, fmt::print(FMT_COMPILE("Don't {}!"), "panic"), "Don't panic!"); EXPECT_WRITE(stderr, fmt::print(stderr, FMT_COMPILE("Don't {}!"), "panic"), "Don't panic!"); + fmt::print(FMT_COMPILE("{}"), std_context_test()); } #endif