From 0b635c9dc5fc29e7f2c4357d0622350fa2e69f93 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 10 Feb 2018 06:17:42 -0800 Subject: [PATCH] Fix handling of fixed enums in clang (#580) --- include/fmt/core.h | 8 ++++++++ test/format-test.cc | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/include/fmt/core.h b/include/fmt/core.h index 7a566e78..ec41ac83 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -82,6 +82,8 @@ # endif #endif +#define FMT_USE_STRONG_ENUMS FMT_HAS_FEATURE(cxx_strong_enums) + // Check if exceptions are disabled. #if defined(__GNUC__) && !defined(__EXCEPTIONS) # define FMT_EXCEPTIONS 0 @@ -583,6 +585,12 @@ void make_value(const T *p) { static_assert(!sizeof(T), "formatting of non-void pointers is disallowed"); } +template +inline typename std::enable_if< + convert_to_int::value && std::is_enum::value, + typed_value>::type + make_value(const T &val) { return static_cast(val); } + template inline typename std::enable_if< !convert_to_int::value, typed_value>::type diff --git a/test/format-test.cc b/test/format-test.cc index f8361fe1..30b59fc2 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1508,6 +1508,14 @@ TEST(FormatTest, Enum) { EXPECT_EQ("0", fmt::format("{}", A)); } +#if FMT_USE_STRONG_ENUMS +enum TestFixedEnum : short { B }; + +TEST(FormatTest, FixedEnum) { + EXPECT_EQ("0", fmt::format("{}", B)); +} +#endif + using buffer_range = fmt::back_insert_range; class mock_arg_formatter :