diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h index 275ab12800..cfe75c4eea 100644 --- a/src/corelib/global/qflags.h +++ b/src/corelib/global/qflags.h @@ -117,13 +117,13 @@ public: : i(initializer_list_helper(flags.begin(), flags.end())) {} #endif - inline QFlags &operator&=(int mask) { i &= mask; return *this; } - inline QFlags &operator&=(uint mask) { i &= mask; return *this; } - inline QFlags &operator&=(Enum mask) { i &= Int(mask); return *this; } - inline QFlags &operator|=(QFlags f) { i |= f.i; return *this; } - inline QFlags &operator|=(Enum f) { i |= Int(f); return *this; } - inline QFlags &operator^=(QFlags f) { i ^= f.i; return *this; } - inline QFlags &operator^=(Enum f) { i ^= Int(f); return *this; } + Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator&=(int mask) { i &= mask; return *this; } + Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator&=(uint mask) { i &= mask; return *this; } + Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator&=(Enum mask) { i &= Int(mask); return *this; } + Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator|=(QFlags f) { i |= f.i; return *this; } + Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator|=(Enum f) { i |= Int(f); return *this; } + Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator^=(QFlags f) { i ^= f.i; return *this; } + Q_DECL_RELAXED_CONSTEXPR inline QFlags &operator^=(Enum f) { i ^= Int(f); return *this; } Q_DECL_CONSTEXPR inline operator Int() const { return i; } diff --git a/tests/auto/corelib/global/qflags/qflags.pro b/tests/auto/corelib/global/qflags/qflags.pro index 9e80d5634b..3f78bc045b 100644 --- a/tests/auto/corelib/global/qflags/qflags.pro +++ b/tests/auto/corelib/global/qflags/qflags.pro @@ -3,3 +3,4 @@ TARGET = tst_qflags QT = core testlib SOURCES = tst_qflags.cpp DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 +contains(QT_CONFIG, c++11): CONFIG += c++11 c++14 diff --git a/tests/auto/corelib/global/qflags/tst_qflags.cpp b/tests/auto/corelib/global/qflags/tst_qflags.cpp index 4c74ac166b..15fe93298d 100644 --- a/tests/auto/corelib/global/qflags/tst_qflags.cpp +++ b/tests/auto/corelib/global/qflags/tst_qflags.cpp @@ -94,6 +94,16 @@ void tst_QFlags::testFlagMultiBits() const template bool verifyConstExpr(T n) { return n == N; } +Q_DECL_RELAXED_CONSTEXPR Qt::MouseButtons testRelaxedConstExpr() +{ + Qt::MouseButtons value; + value = Qt::LeftButton | Qt::RightButton; + value |= Qt::MiddleButton; + value &= ~Qt::LeftButton; + value ^= Qt::RightButton; + return value; +} + void tst_QFlags::constExpr() { #ifdef Q_COMPILER_CONSTEXPR @@ -115,6 +125,10 @@ void tst_QFlags::constExpr() QVERIFY(verifyConstExpr(0xff)); QVERIFY(!verifyConstExpr(!Qt::MouseButtons(Qt::LeftButton))); + +#if defined(__cpp_constexpr) && __cpp_constexpr-0 >= 201304 + QVERIFY(verifyConstExpr(Qt::MiddleButton)); +#endif #endif }