1
0
Fork 0
mirror of https://github.com/Neargye/magic_enum.git synced 2026-01-09 23:34:23 +00:00

Support gcc -fno-pretty-templates (#258)

https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-fno-pretty-templates

The gcc option -fno-pretty-templates changes the __PRETTY_FUNCTION__ from e.g.
"auto n() [with E = E]" to "auto n<E>()" (more like MSVC).

Pass the entire __PRETTY_FUNCTION__ / __FUNCSIG__ to pretty_name(), and truncate it there, checking the last character if necessary to determine the format used.
This commit is contained in:
Ed Catmur 2023-05-13 04:15:23 -05:00 committed by GitHub
parent d4fa0c3dd3
commit 5367f5183c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -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