diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index 8e20dc1..319e1c9 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -122,18 +122,19 @@ inline constexpr auto range_v = range_impl(); return {}; // Invalid name. } +template +struct always_false final : std::false_type {}; + template -[[nodiscard]] constexpr std::string_view name_impl() noexcept { +[[nodiscard]] constexpr auto name_impl() noexcept { static_assert(std::is_enum_v, "magic_enum::detail::name_impl requires enum type."); -#if defined(__clang__) +#if defined(__clang__) || defined(__GNUC__) && __GNUC__ >= 9 return pretty_name({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 2}); -#elif defined(__GNUC__) && __GNUC__ >= 9 - return pretty_name({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 51}); #elif defined(_MSC_VER) return pretty_name({__FUNCSIG__, sizeof(__FUNCSIG__) - 17}); #else -# error "magic_enum: Unsupported compiler (https://github.com/Neargye/magic_enum#compiler-compatibility)." - return {}; // Unsupported compiler. + static_assert(always_false{}, "magic_enum: Unsupported compiler (https://github.com/Neargye/magic_enum#compiler-compatibility)."); + return std::string_view{}; // Unsupported compiler. #endif }