From 63271a51c4292915beb4f45d8816a6d75838caa0 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 20 May 2021 06:13:13 -0700 Subject: [PATCH] Fix ADL issues --- include/fmt/core.h | 10 +++++----- test/core-test.cc | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 1f79b50e..cfb6fcbd 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -2816,7 +2816,7 @@ template ::value)> inline auto format_to(OutputIt out, format_string fmt, T&&... args) -> OutputIt { - return vformat_to(out, fmt, make_format_args(args...)); + return vformat_to(out, fmt, fmt::make_format_args(args...)); } template struct format_to_n_result { @@ -2848,14 +2848,14 @@ template ::value)> inline auto format_to_n(OutputIt out, size_t n, format_string fmt, const T&... args) -> format_to_n_result { - return vformat_to_n(out, n, fmt, make_format_args(args...)); + return vformat_to_n(out, n, fmt, fmt::make_format_args(args...)); } /** Returns the number of chars in the output of ``format(fmt, args...)``. */ template inline auto formatted_size(format_string fmt, T&&... args) -> size_t { auto buf = detail::counting_buffer<>(); - detail::vformat_to(buf, string_view(fmt), make_format_args(args...)); + detail::vformat_to(buf, string_view(fmt), fmt::make_format_args(args...)); return buf.count(); } @@ -2874,7 +2874,7 @@ FMT_API void vprint(std::FILE*, string_view, format_args); */ template inline void print(format_string fmt, T&&... args) { - const auto& vargs = make_format_args(args...); + const auto& vargs = fmt::make_format_args(args...); return detail::is_utf8() ? vprint(fmt, vargs) : detail::vprint_mojibake(stdout, fmt, vargs); } @@ -2891,7 +2891,7 @@ inline void print(format_string fmt, T&&... args) { */ template inline void print(std::FILE* f, format_string fmt, T&&... args) { - const auto& vargs = make_format_args(args...); + const auto& vargs = fmt::make_format_args(args...); return detail::is_utf8() ? vprint(f, fmt, vargs) : detail::vprint_mojibake(f, fmt, vargs); } diff --git a/test/core-test.cc b/test/core-test.cc index 93ee1027..de1ac225 100644 --- a/test/core-test.cc +++ b/test/core-test.cc @@ -846,3 +846,24 @@ struct disabled_rvalue_conversion { TEST(core_test, disabled_rvalue_conversion) { EXPECT_EQ("foo", fmt::format("{}", disabled_rvalue_conversion())); } + +namespace adl_test { +template void make_format_args(const T&...) = delete; + +struct string : std::string {}; +} // namespace adl_test + +// Test that formatting functions compile when make_format_args is found by ADL. +TEST(core_test, adl) { + // Only check compilation and don't run the code to avoid polluting the output + // and since the output is tested elsewhere. + if (fmt::detail::const_check(true)) return; + auto s = adl_test::string(); + char buf[10]; + fmt::format("{}", s); + fmt::format_to(buf, "{}", s); + fmt::format_to_n(buf, 10, "{}", s); + fmt::formatted_size("{}", s); + fmt::print("{}", s); + fmt::print(stdout, "{}", s); +}