diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index f17414a..c798627 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -425,8 +425,12 @@ constexpr auto n() noexcept { #if defined(MAGIC_ENUM_GET_TYPE_NAME_BUILTIN) constexpr auto name_ptr = MAGIC_ENUM_GET_TYPE_NAME_BUILTIN(E); constexpr auto name = name_ptr ? string_view{ name_ptr } : std::string_view{}; -#elif defined(__clang__) || defined(__GNUC__) +#elif defined(__clang__) constexpr auto name = pretty_name({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 2}); +#elif defined(__GNUC__) + auto name = string_view{__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1}; + name.remove_suffix(name[name.size() - 1] == ']' ? 1 : 3); + name = pretty_name(name); #elif defined(_MSC_VER) constexpr auto name = pretty_name({__FUNCSIG__, sizeof(__FUNCSIG__) - 17}); #else @@ -469,8 +473,12 @@ constexpr auto n() noexcept { #if defined(MAGIC_ENUM_GET_ENUM_NAME_BUILTIN) constexpr auto name_ptr = MAGIC_ENUM_GET_ENUM_NAME_BUILTIN(V); constexpr auto name = name_ptr ? string_view{ name_ptr } : std::string_view{}; -#elif defined(__clang__) || defined(__GNUC__) +#elif defined(__clang__) constexpr auto name = pretty_name({__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 2}); +#elif defined(__GNUC__) + auto name = string_view{__PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1}; + name.remove_suffix(name[name.size() - 1] == ']' ? 1 : 3); + name = pretty_name(name); #elif defined(_MSC_VER) constexpr auto name = pretty_name({__FUNCSIG__, sizeof(__FUNCSIG__) - 17}); #else diff --git a/test/test_aliases.cpp b/test/test_aliases.cpp index 709033c..a57a587 100644 --- a/test/test_aliases.cpp +++ b/test/test_aliases.cpp @@ -76,6 +76,7 @@ struct MyStringView { constexpr std::size_t find(char c) const { return str.find(c); } // required constexpr MyStringView substr(std::size_t p, std::size_t n) { return str.substr(p, n); } // required constexpr void remove_prefix(std::size_t n) { str.remove_prefix(n); } // required + constexpr void remove_suffix(std::size_t n) { str.remove_suffix(n); } // required friend constexpr bool operator==(MyStringView lhs, MyStringView rhs); // required constexpr MyStringView(const char* cstr) : str{ cstr } {}