From 471dfa4f604d2506076d5b38b787e7a3c979e57c Mon Sep 17 00:00:00 2001 From: Egor Seredin Date: Thu, 29 Aug 2019 18:14:18 +0900 Subject: [PATCH 1/2] Map not int enum to correct underlying_type --- include/fmt/core.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 2dc6ed552bbb..cb7f6185fb81 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -824,8 +824,8 @@ template struct arg_mapper { FMT_ENABLE_IF(std::is_enum::value && !has_formatter::value && !has_fallback_formatter::value)> - FMT_CONSTEXPR int map(const T& val) { - return static_cast(val); + FMT_CONSTEXPR auto map(const T& val) -> decltype(map(static_cast::type>(val))) { + return map(static_cast::type>(val)); } template ::value && !is_char::value && From 93d1d1507d61d4d3fe0585ec148126c88b7b1efb Mon Sep 17 00:00:00 2001 From: Egor Seredin Date: Thu, 29 Aug 2019 20:01:50 +0900 Subject: [PATCH 2/2] Use non-zero constant in TestFixedEnum --- test/format-test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/format-test.cc b/test/format-test.cc index ffa0a9b276fc..3d619e50932a 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -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;