Commit 0b635c9d authored by Victor Zverovich's avatar Victor Zverovich

Fix handling of fixed enums in clang (#580)

parent 66afd9b3
...@@ -82,6 +82,8 @@ ...@@ -82,6 +82,8 @@
# endif # endif
#endif #endif
#define FMT_USE_STRONG_ENUMS FMT_HAS_FEATURE(cxx_strong_enums)
// Check if exceptions are disabled. // Check if exceptions are disabled.
#if defined(__GNUC__) && !defined(__EXCEPTIONS) #if defined(__GNUC__) && !defined(__EXCEPTIONS)
# define FMT_EXCEPTIONS 0 # define FMT_EXCEPTIONS 0
...@@ -583,6 +585,12 @@ void make_value(const T *p) { ...@@ -583,6 +585,12 @@ void make_value(const T *p) {
static_assert(!sizeof(T), "formatting of non-void pointers is disallowed"); static_assert(!sizeof(T), "formatting of non-void pointers is disallowed");
} }
template <typename C, typename T>
inline typename std::enable_if<
convert_to_int<T>::value && std::is_enum<T>::value,
typed_value<C, INT>>::type
make_value(const T &val) { return static_cast<int>(val); }
template <typename C, typename T> template <typename C, typename T>
inline typename std::enable_if< inline typename std::enable_if<
!convert_to_int<T>::value, typed_value<C, CUSTOM>>::type !convert_to_int<T>::value, typed_value<C, CUSTOM>>::type
......
...@@ -1508,6 +1508,14 @@ TEST(FormatTest, Enum) { ...@@ -1508,6 +1508,14 @@ TEST(FormatTest, Enum) {
EXPECT_EQ("0", fmt::format("{}", A)); 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<fmt::internal::buffer>; using buffer_range = fmt::back_insert_range<fmt::internal::buffer>;
class mock_arg_formatter : class mock_arg_formatter :
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment