From dcd282bb268a0766f6d273b6e41a3a96719bbbfb Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 9 Oct 2021 06:43:48 -0700 Subject: [PATCH] Namespace qualify calls to get --- include/fmt/compile.h | 11 +++++++---- test/compile-test.cc | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 97e1240e..059262f9 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -190,7 +190,7 @@ constexpr const auto& get([[maybe_unused]] const T& first, if constexpr (N == 0) return first; else - return get(rest...); + return detail::get(rest...); } template @@ -202,7 +202,8 @@ constexpr int get_arg_index_by_name(basic_string_view name, template struct get_type_impl; template struct get_type_impl> { - using type = remove_cvref_t(std::declval()...))>; + using type = + remove_cvref_t(std::declval()...))>; }; template @@ -242,7 +243,7 @@ template struct code_unit { // This ensures that the argument type is convertible to `const T&`. template constexpr const T& get_arg_checked(const Args&... args) { - const auto& arg = get(args...); + const auto& arg = detail::get(args...); if constexpr (detail::is_named_arg>()) { return arg.value; } else { @@ -399,7 +400,9 @@ template struct arg_id_handler { return 0; } - constexpr void on_error(const char* message) { FMT_THROW(format_error(message)); } + constexpr void on_error(const char* message) { + FMT_THROW(format_error(message)); + } }; template struct parse_arg_id_result { diff --git a/test/compile-test.cc b/test/compile-test.cc index fe2ca110..28eef2a2 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -59,6 +59,23 @@ TEST(compile_test, compile_fallback) { EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), 42)); } +struct type_with_get { + template friend void get(type_with_get); +}; + +FMT_BEGIN_NAMESPACE +template <> struct formatter : formatter { + template + auto format(type_with_get, FormatContext& ctx) -> decltype(ctx.out()) { + return formatter::format(42, ctx); + } +}; +FMT_END_NAMESPACE + +TEST(compile_test, compile_type_with_get) { + EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), type_with_get())); +} + #ifdef __cpp_if_constexpr struct test_formattable {};