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

Fix __FUNCSIG__ parsing on x86 by explicitly declaring the calling convention (#405)

This commit is contained in:
Ryan Saunders 2025-06-27 04:25:18 -07:00 committed by GitHub
parent ca429575e0
commit ecdeb1cea5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -98,6 +98,14 @@
# define MAGIC_ENUM_SUPPORTED_ALIASES 1 # define MAGIC_ENUM_SUPPORTED_ALIASES 1
#endif #endif
// Specify the calling convention for compilers that need it in order to get reliable mangled names under different
// compiler flags. In particular, MSVC allows changing the default calling convention on x86.
#if defined(__clang__) || defined(__GNUC__)
#define MAGIC_ENUM_CALLING_CONVENTION
#elif defined(_MSC_VER)
#define MAGIC_ENUM_CALLING_CONVENTION __cdecl
#endif
// Enum value must be greater or equals than MAGIC_ENUM_RANGE_MIN. By default MAGIC_ENUM_RANGE_MIN = -128. // Enum value must be greater or equals than MAGIC_ENUM_RANGE_MIN. By default MAGIC_ENUM_RANGE_MIN = -128.
// If need another min range for all enum types by default, redefine the macro MAGIC_ENUM_RANGE_MIN. // If need another min range for all enum types by default, redefine the macro MAGIC_ENUM_RANGE_MIN.
#if !defined(MAGIC_ENUM_RANGE_MIN) #if !defined(MAGIC_ENUM_RANGE_MIN)
@ -456,7 +464,7 @@ template <typename T>
inline constexpr bool is_enum_v = std::is_enum_v<T> && std::is_same_v<T, std::decay_t<T>>; inline constexpr bool is_enum_v = std::is_enum_v<T> && std::is_same_v<T, std::decay_t<T>>;
template <typename E> template <typename E>
constexpr auto n() noexcept { constexpr auto MAGIC_ENUM_CALLING_CONVENTION n() noexcept {
static_assert(is_enum_v<E>, "magic_enum::detail::n requires enum type."); static_assert(is_enum_v<E>, "magic_enum::detail::n requires enum type.");
if constexpr (supported<E>::value) { if constexpr (supported<E>::value) {
@ -532,7 +540,7 @@ template <typename E>
inline constexpr auto type_name_v = type_name<E>(); inline constexpr auto type_name_v = type_name<E>();
template <auto V> template <auto V>
constexpr auto n() noexcept { constexpr auto MAGIC_ENUM_CALLING_CONVENTION n() noexcept {
static_assert(is_enum_v<decltype(V)>, "magic_enum::detail::n requires enum type."); static_assert(is_enum_v<decltype(V)>, "magic_enum::detail::n requires enum type.");
if constexpr (supported<decltype(V)>::value) { if constexpr (supported<decltype(V)>::value) {
@ -604,7 +612,7 @@ constexpr auto n() noexcept {
#if defined(MAGIC_ENUM_VS_2017_WORKAROUND) #if defined(MAGIC_ENUM_VS_2017_WORKAROUND)
template <typename E, E V> template <typename E, E V>
constexpr auto n() noexcept { constexpr auto MAGIC_ENUM_CALLING_CONVENTION n() noexcept {
static_assert(is_enum_v<E>, "magic_enum::detail::n requires enum type."); static_assert(is_enum_v<E>, "magic_enum::detail::n requires enum type.");
# if defined(MAGIC_ENUM_GET_ENUM_NAME_BUILTIN) # if defined(MAGIC_ENUM_GET_ENUM_NAME_BUILTIN)