From 9328a074b1ea3722476e63796c6a0c2115cd893d Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 14 Oct 2017 08:47:08 -0700 Subject: [PATCH] Fix handling of fixed enums in clang (#580) --- fmt/format.h | 14 ++++++++++++++ test/format-test.cc | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/fmt/format.h b/fmt/format.h index c02a301e..30f0e478 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -1405,6 +1405,20 @@ class MakeValue : public Arg { FMT_MAKE_VALUE(unsigned char, uint_value, UINT) FMT_MAKE_VALUE(char, int_value, CHAR) +#if __cplusplus >= 201103L + template < + typename T, + typename = typename std::enable_if< + std::is_enum::value && ConvertToInt::value>::type> + MakeValue(T value) { int_value = value; } + + template < + typename T, + typename = typename std::enable_if< + std::is_enum::value && ConvertToInt::value>::type> + static uint64_t type(T value) { return Arg::INT; } +#endif + #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) MakeValue(typename WCharHelper::Supported value) { int_value = value; diff --git a/test/format-test.cc b/test/format-test.cc index 3fb2a78b..7160972e 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1681,6 +1681,14 @@ TEST(FormatTest, Enum) { EXPECT_EQ("0", fmt::format("{}", A)); } +#if __cplusplus >= 201103L +enum TestFixedEnum : short { B }; + +TEST(FormatTest, FixedEnum) { + EXPECT_EQ("0", fmt::format("{}", B)); +} +#endif + class MockArgFormatter : public fmt::internal::ArgFormatterBase { public: