Skip to content

Commit

Permalink
Fix overload ambiguity in arg_mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Aug 26, 2021
1 parent b9ce56d commit 6d597e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,8 @@ template <typename Context> struct arg_mapper {
FMT_CONSTEXPR FMT_INLINE auto map(const char_type* val) -> const char_type* {
return val;
}
template <typename T, FMT_ENABLE_IF(is_string<T>::value)>
template <typename T,
FMT_ENABLE_IF(is_string<T>::value && !std::is_pointer<T>::value)>
FMT_CONSTEXPR FMT_INLINE auto map(const T& val)
-> basic_string_view<char_type> {
static_assert(std::is_same<char_type, char_t<T>>::value,
Expand Down Expand Up @@ -1324,9 +1325,8 @@ template <typename Context> struct arg_mapper {

// We use SFINAE instead of a const T* parameter to avoid conflicting with
// the C array overload.
template <typename T>
FMT_CONSTEXPR auto map(T)
-> enable_if_t<std::is_pointer<T>::value, unformattable_pointer> {
template <typename T, FMT_ENABLE_IF(std::is_pointer<T>::value)>
FMT_CONSTEXPR auto map(T) -> unformattable_pointer {
return {};
}

Expand Down
4 changes: 4 additions & 0 deletions test/xchar-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ TEST(xchar_test, format) {
EXPECT_EQ(L"abc1", fmt::format(L"{}c{}", L"ab", 1));
}

TEST(xchar_test, is_formattable) {
static_assert(!fmt::is_formattable<const wchar_t*>::value, "");
}

TEST(xchar_test, compile_time_string) {
#if defined(FMT_USE_STRING_VIEW) && __cplusplus >= 201703L
EXPECT_EQ(L"42", fmt::format(FMT_STRING(std::wstring_view(L"{}")), 42));
Expand Down

0 comments on commit 6d597e3

Please sign in to comment.