mirror of
https://git.code.sf.net/p/mingw-w64/mingw-w64
synced 2024-11-23 01:44:43 +08:00
include/winnt: Fix constexpr-ness of compound assignment operators of enum types
Previously they cast their first enum operands to `int&` and operate on integers, which is type-punning and maybe not safe. This commit makes them call the corresponding non-assignment operators instead. As they modify their arguments, they are only `constexpr` since C++14. Also regroup them a little. Signed-off-by: LIU Hao <lh_mouse@126.com>
This commit is contained in:
parent
c6857dc97a
commit
cf5c50cce0
@ -706,13 +706,13 @@ typedef LONG RTL_REFERENCE_COUNT32, *PRTL_REFERENCE_COUNT32;
|
||||
#ifdef __cplusplus
|
||||
#define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \
|
||||
extern "C++" { \
|
||||
__MINGW_CXX11_CONSTEXPR inline ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) | ((int)b)); } \
|
||||
__MINGW_CXX11_CONSTEXPR inline ENUMTYPE &operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) |= ((int)b)); } \
|
||||
__MINGW_CXX11_CONSTEXPR inline ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) & ((int)b)); } \
|
||||
__MINGW_CXX11_CONSTEXPR inline ENUMTYPE &operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) &= ((int)b)); } \
|
||||
__MINGW_CXX11_CONSTEXPR inline ENUMTYPE operator ~ (ENUMTYPE a) { return ENUMTYPE(~((int)a)); } \
|
||||
__MINGW_CXX11_CONSTEXPR inline ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) | ((int)b)); } \
|
||||
__MINGW_CXX11_CONSTEXPR inline ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) & ((int)b)); } \
|
||||
__MINGW_CXX11_CONSTEXPR inline ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) ^ ((int)b)); } \
|
||||
__MINGW_CXX11_CONSTEXPR inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) ^= ((int)b)); } \
|
||||
__MINGW_CXX14_CONSTEXPR inline ENUMTYPE& operator |= (ENUMTYPE& a, ENUMTYPE b) { return a = a | b; } \
|
||||
__MINGW_CXX14_CONSTEXPR inline ENUMTYPE& operator &= (ENUMTYPE& a, ENUMTYPE b) { return a = a & b; } \
|
||||
__MINGW_CXX14_CONSTEXPR inline ENUMTYPE& operator ^= (ENUMTYPE& a, ENUMTYPE b) { return a = a ^ b; } \
|
||||
}
|
||||
#else
|
||||
#define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) /* */
|
||||
|
Loading…
Reference in New Issue
Block a user