QFlags: fix missing bitwise xor operators in QT_TYPESAFE_FLAGS builds
Add tests that cover them. Pick-to: 6.3 Fixes: QTBUG-101300 Change-Id: I5a8af4a91d796cc4d287b813bd5cc13da3d7e766 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
324887779d
commit
6f50e54138
@ -233,6 +233,10 @@ constexpr inline QFlags<Flags::enum_type> operator&(Flags::enum_type f1, Flags::
|
||||
{ return QFlags<Flags::enum_type>(f1) & f2; } \
|
||||
constexpr inline QFlags<Flags::enum_type> operator&(Flags::enum_type f1, QFlags<Flags::enum_type> f2) noexcept \
|
||||
{ return f2 & f1; } \
|
||||
constexpr inline QFlags<Flags::enum_type> operator^(Flags::enum_type f1, Flags::enum_type f2) noexcept \
|
||||
{ return QFlags<Flags::enum_type>(f1) ^ f2; } \
|
||||
constexpr inline QFlags<Flags::enum_type> operator^(Flags::enum_type f1, QFlags<Flags::enum_type> f2) noexcept \
|
||||
{ return f2 ^ f1; } \
|
||||
constexpr inline void operator+(Flags::enum_type f1, Flags::enum_type f2) noexcept = delete; \
|
||||
constexpr inline void operator+(Flags::enum_type f1, QFlags<Flags::enum_type> f2) noexcept = delete; \
|
||||
constexpr inline void operator+(int f1, QFlags<Flags::enum_type> f2) noexcept = delete; \
|
||||
|
@ -33,6 +33,7 @@ class tst_QFlags: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void operators() const;
|
||||
void testFlag() const;
|
||||
void testFlagZeroFlag() const;
|
||||
void testFlagMultiBits() const;
|
||||
@ -46,6 +47,28 @@ private slots:
|
||||
void adl();
|
||||
};
|
||||
|
||||
void tst_QFlags::operators() const
|
||||
{
|
||||
#define CHECK(op, LHS, RHS, RES) \
|
||||
do { \
|
||||
QCOMPARE((LHS op RHS), (RES)); \
|
||||
QCOMPARE(( /*CTAD*/ QFlags(LHS) op RHS), (RES)); \
|
||||
QCOMPARE((LHS op QFlags(RHS)), (RES)); \
|
||||
QCOMPARE((QFlags(LHS) op QFlags(RHS)), (RES)); \
|
||||
QCOMPARE((QFlags(LHS) op ## = RHS), (RES)); \
|
||||
QCOMPARE((QFlags(LHS) op ## = QFlags(RHS)), (RES)); \
|
||||
} while (false)
|
||||
|
||||
CHECK(|, Qt::AlignHCenter, Qt::AlignVCenter, Qt::AlignCenter);
|
||||
CHECK(|, Qt::AlignHCenter, Qt::AlignHCenter, Qt::AlignHCenter);
|
||||
CHECK(&, Qt::AlignHCenter, Qt::AlignVCenter, Qt::Alignment());
|
||||
CHECK(&, Qt::AlignHCenter, Qt::AlignHCenter, Qt::AlignHCenter);
|
||||
CHECK(^, Qt::AlignHCenter, Qt::AlignVCenter, Qt::AlignCenter);
|
||||
CHECK(^, Qt::AlignHCenter, Qt::AlignHCenter, Qt::Alignment());
|
||||
|
||||
#undef CHECK
|
||||
}
|
||||
|
||||
void tst_QFlags::testFlag() const
|
||||
{
|
||||
Qt::MouseButtons btn = Qt::LeftButton | Qt::RightButton;
|
||||
|
Loading…
x
Reference in New Issue
Block a user