diff --git a/include/fmt/core.h b/include/fmt/core.h index 642923b5..9a00668d 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1350,7 +1350,7 @@ inline auto format_as(std::byte b) -> unsigned char { template struct has_format_as { template ::value&& std::is_integral::value)> + FMT_ENABLE_IF(std::is_enum::value)> static auto check(U*) -> std::true_type; static auto check(...) -> std::false_type; diff --git a/test/core-test.cc b/test/core-test.cc index 0d176241..75168dcd 100644 --- a/test/core-test.cc +++ b/test/core-test.cc @@ -677,6 +677,9 @@ namespace test { enum class scoped_enum_as_int {}; auto format_as(scoped_enum_as_int) -> int { return 42; } +enum class scoped_enum_as_string {}; +auto format_as(scoped_enum_as_string) -> fmt::string_view { return "foo"; } + struct convertible_to_enum { operator scoped_enum_as_int() const { return {}; } }; @@ -734,6 +737,7 @@ TEST(core_test, format_to) { TEST(core_test, format_as) { EXPECT_EQ(fmt::format("{}", test::scoped_enum_as_int()), "42"); + EXPECT_EQ(fmt::format("{}", test::scoped_enum_as_string()), "foo"); } #ifdef __cpp_lib_byte