Skip to content

Commit

Permalink
Map not int enum to correct underlying_type (#1286)
Browse files Browse the repository at this point in the history
* Map not int enum to correct underlying_type

* Use non-zero constant in TestFixedEnum
  • Loading branch information
agmt authored and vitaut committed Aug 31, 2019
1 parent 345ba07 commit bcd9b93
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,8 @@ template <typename Context> struct arg_mapper {
FMT_ENABLE_IF(std::is_enum<T>::value &&
!has_formatter<T, Context>::value &&
!has_fallback_formatter<T, Context>::value)>
FMT_CONSTEXPR int map(const T& val) {
return static_cast<int>(val);
FMT_CONSTEXPR auto map(const T& val) -> decltype(map(static_cast<typename std::underlying_type<T>::type>(val))) {
return map(static_cast<typename std::underlying_type<T>::type>(val));
}
template <typename T,
FMT_ENABLE_IF(!is_string<T>::value && !is_char<T>::value &&
Expand Down
4 changes: 2 additions & 2 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1906,9 +1906,9 @@ TEST(FormatTest, FormatterNotSpecialized) {
}

#if FMT_HAS_FEATURE(cxx_strong_enums)
enum TestFixedEnum : short { B };
enum TestFixedEnum : short { B = 1 };

TEST(FormatTest, FixedEnum) { EXPECT_EQ("0", fmt::format("{}", B)); }
TEST(FormatTest, FixedEnum) { EXPECT_EQ("1", fmt::format("{}", B)); }
#endif

using buffer_range = fmt::buffer_range<char>;
Expand Down

0 comments on commit bcd9b93

Please sign in to comment.