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

Move calling convention into a macro that can be defined per-compiler

This commit is contained in:
Ryan Saunders 2025-06-24 10:08:45 -07:00
parent 52054c7289
commit c4d533d9d2

View file

@ -98,6 +98,14 @@
# define MAGIC_ENUM_SUPPORTED_ALIASES 1
#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.
// If need another min range for all enum types by default, redefine the macro MAGIC_ENUM_RANGE_MIN.
#if !defined(MAGIC_ENUM_RANGE_MIN)
@ -418,7 +426,7 @@ template <typename T>
inline constexpr bool is_enum_v = std::is_enum_v<T> && std::is_same_v<T, std::decay_t<T>>;
template <typename E>
constexpr auto __cdecl n() noexcept {
constexpr auto MAGIC_ENUM_CALLING_CONVENTION n() noexcept {
static_assert(is_enum_v<E>, "magic_enum::detail::n requires enum type.");
if constexpr (supported<E>::value) {
@ -494,7 +502,7 @@ template <typename E>
inline constexpr auto type_name_v = type_name<E>();
template <auto V>
constexpr auto __cdecl n() noexcept {
constexpr auto MAGIC_ENUM_CALLING_CONVENTION n() noexcept {
static_assert(is_enum_v<decltype(V)>, "magic_enum::detail::n requires enum type.");
if constexpr (supported<decltype(V)>::value) {
@ -566,7 +574,7 @@ constexpr auto __cdecl n() noexcept {
#if defined(MAGIC_ENUM_VS_2017_WORKAROUND)
template <typename E, E V>
constexpr auto __cdecl n() noexcept {
constexpr auto MAGIC_ENUM_CALLING_CONVENTION n() noexcept {
static_assert(is_enum_v<E>, "magic_enum::detail::n requires enum type.");
# if defined(MAGIC_ENUM_GET_ENUM_NAME_BUILTIN)