Skip to content

Commit

Permalink
Namespace qualify calls to get
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Oct 9, 2021
1 parent 9c14474 commit dcd282b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
11 changes: 7 additions & 4 deletions include/fmt/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ constexpr const auto& get([[maybe_unused]] const T& first,
if constexpr (N == 0)
return first;
else
return get<N - 1>(rest...);
return detail::get<N - 1>(rest...);
}

template <typename Char, typename... Args>
Expand All @@ -202,7 +202,8 @@ constexpr int get_arg_index_by_name(basic_string_view<Char> name,
template <int N, typename> struct get_type_impl;

template <int N, typename... Args> struct get_type_impl<N, type_list<Args...>> {
using type = remove_cvref_t<decltype(get<N>(std::declval<Args>()...))>;
using type =
remove_cvref_t<decltype(detail::get<N>(std::declval<Args>()...))>;
};

template <int N, typename T>
Expand Down Expand Up @@ -242,7 +243,7 @@ template <typename Char> struct code_unit {
// This ensures that the argument type is convertible to `const T&`.
template <typename T, int N, typename... Args>
constexpr const T& get_arg_checked(const Args&... args) {
const auto& arg = get<N>(args...);
const auto& arg = detail::get<N>(args...);
if constexpr (detail::is_named_arg<remove_cvref_t<decltype(arg)>>()) {
return arg.value;
} else {
Expand Down Expand Up @@ -399,7 +400,9 @@ template <typename Char> 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 <typename Char> struct parse_arg_id_result {
Expand Down
17 changes: 17 additions & 0 deletions test/compile-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ TEST(compile_test, compile_fallback) {
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), 42));
}

struct type_with_get {
template <int> friend void get(type_with_get);
};

FMT_BEGIN_NAMESPACE
template <> struct formatter<type_with_get> : formatter<int> {
template <typename FormatContext>
auto format(type_with_get, FormatContext& ctx) -> decltype(ctx.out()) {
return formatter<int>::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 {};

Expand Down

0 comments on commit dcd282b

Please sign in to comment.