Skip to content

Commit

Permalink
Fix ADL issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed May 20, 2021
1 parent 61b4c92 commit 63271a5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
10 changes: 5 additions & 5 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -2816,7 +2816,7 @@ template <typename OutputIt, typename... T,
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
inline auto format_to(OutputIt out, format_string<T...> fmt, T&&... args)
-> OutputIt {
return vformat_to(out, fmt, make_format_args(args...));
return vformat_to(out, fmt, fmt::make_format_args(args...));
}

template <typename OutputIt> struct format_to_n_result {
Expand Down Expand Up @@ -2848,14 +2848,14 @@ template <typename OutputIt, typename... T,
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
inline auto format_to_n(OutputIt out, size_t n, format_string<T...> fmt,
const T&... args) -> format_to_n_result<OutputIt> {
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 <typename... T>
inline auto formatted_size(format_string<T...> 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();
}

Expand All @@ -2874,7 +2874,7 @@ FMT_API void vprint(std::FILE*, string_view, format_args);
*/
template <typename... T>
inline void print(format_string<T...> 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);
}
Expand All @@ -2891,7 +2891,7 @@ inline void print(format_string<T...> fmt, T&&... args) {
*/
template <typename... T>
inline void print(std::FILE* f, format_string<T...> 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);
}
Expand Down
21 changes: 21 additions & 0 deletions test/core-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename... T> 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);
}

0 comments on commit 63271a5

Please sign in to comment.