diff options
author | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2023-06-09 17:30:54 +0300 |
---|---|---|
committer | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2023-06-09 17:30:54 +0300 |
commit | da6e958319e95fe564d3b30c931492dd666bfaff (patch) | |
tree | 16ac1556a573daeba5c9c4b795f86aa166ffe467 /src/corelib/global/qflags.h | |
parent | 29400a683f96867133b28299c0d0bd6bcf40df35 (diff) | |
parent | a96fc76fa78f3500266b3a34016f9e1bd29b319c (diff) |
Merge remote-tracking branch 'origin/tqtc/lts-5.15.11' into tqtc/lts-5.15-opensourcev5.15.11-lts-lgpl
Change-Id: Iac056a5e9f59fc8d1929171c18039aeb45be22b8
Diffstat (limited to 'src/corelib/global/qflags.h')
-rw-r--r-- | src/corelib/global/qflags.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h index 4f46de5eaa..0fb0f8c6ae 100644 --- a/src/corelib/global/qflags.h +++ b/src/corelib/global/qflags.h @@ -192,6 +192,33 @@ typedef uint Flags; #endif /* Q_NO_TYPESAFE_FLAGS */ +// restore bit-wise enum-enum operators deprecated in C++20, +// but used in a few places in the API +#if __cplusplus > 201702L // assume compilers don't warn if in C++17 mode + // in C++20 mode, provide user-defined operators to override the deprecated operations: +# define Q_DECLARE_MIXED_ENUM_OPERATOR(op, Ret, LHS, RHS) \ + constexpr inline Ret operator op (LHS lhs, RHS rhs) noexcept \ + { return static_cast<Ret>(std::underlying_type_t<LHS>(lhs) op std::underlying_type_t<RHS>(rhs)); } \ + /* end */ +#else + // in C++11-17 mode, statically-assert that this compiler's result of the + // operation is the same that the C++20 version would produce: +# define Q_DECLARE_MIXED_ENUM_OPERATOR(op, Ret, LHS, RHS) \ + Q_STATIC_ASSERT((std::is_same<decltype(std::declval<LHS>() op std::declval<RHS>()), Ret>::value)); +#endif + +#define Q_DECLARE_MIXED_ENUM_OPERATORS(Ret, Flags, Enum) \ + Q_DECLARE_MIXED_ENUM_OPERATOR(|, Ret, Flags, Enum) \ + Q_DECLARE_MIXED_ENUM_OPERATOR(&, Ret, Flags, Enum) \ + Q_DECLARE_MIXED_ENUM_OPERATOR(^, Ret, Flags, Enum) \ + /* end */ + +#define Q_DECLARE_MIXED_ENUM_OPERATORS_SYMMETRIC(Ret, Flags, Enum) \ + Q_DECLARE_MIXED_ENUM_OPERATORS(Ret, Flags, Enum) \ + Q_DECLARE_MIXED_ENUM_OPERATORS(Ret, Enum, Flags) \ + /* end */ + + QT_END_NAMESPACE #endif // QFLAGS_H |