diff --git a/src/corelib/global/qendian_p.h b/src/corelib/global/qendian_p.h index 9e31f7940a..8d96eba60c 100644 --- a/src/corelib/global/qendian_p.h +++ b/src/corelib/global/qendian_p.h @@ -20,81 +20,6 @@ QT_BEGIN_NAMESPACE -// Note if using multiple of these bitfields in a union; the underlying storage type must -// match. Since we always use an unsigned storage type, unsigned and signed versions may -// be used together, but different bit-widths may not. -template -class QSpecialIntegerBitfield -{ -protected: - typedef typename S::StorageType T; - typedef typename std::make_unsigned::type UT; - - static constexpr UT mask() - { - return ((UT(1) << width) - 1) << pos; - } -public: - // FIXME: val is public until qtdeclarative is fixed to not access it directly. - UT val; - - QSpecialIntegerBitfield &operator=(T t) - { - UT i = S::fromSpecial(val); - i &= ~mask(); - i |= (UT(t) << pos) & mask(); - val = S::toSpecial(i); - return *this; - } - operator T() const - { - if (std::is_signed::value) { - UT i = S::fromSpecial(val); - i <<= (sizeof(T) * 8) - width - pos; - T t = T(i); - t >>= (sizeof(T) * 8) - width; - return t; - } - return (S::fromSpecial(val) & mask()) >> pos; - } - - bool operator!() const { return !(val & S::toSpecial(mask())); } - bool operator==(QSpecialIntegerBitfield i) const - { - return ((val ^ i.val) & S::toSpecial(mask())) == 0; - } - bool operator!=(QSpecialIntegerBitfield i) const - { - return ((val ^ i.val) & S::toSpecial(mask())) != 0; - } - - QSpecialIntegerBitfield &operator+=(T i) { return (*this = (T(*this) + i)); } - QSpecialIntegerBitfield &operator-=(T i) { return (*this = (T(*this) - i)); } - QSpecialIntegerBitfield &operator*=(T i) { return (*this = (T(*this) * i)); } - QSpecialIntegerBitfield &operator/=(T i) { return (*this = (T(*this) / i)); } - QSpecialIntegerBitfield &operator%=(T i) { return (*this = (T(*this) % i)); } - QSpecialIntegerBitfield &operator|=(T i) { return (*this = (T(*this) | i)); } - QSpecialIntegerBitfield &operator&=(T i) { return (*this = (T(*this) & i)); } - QSpecialIntegerBitfield &operator^=(T i) { return (*this = (T(*this) ^ i)); } - QSpecialIntegerBitfield &operator>>=(T i) { return (*this = (T(*this) >> i)); } - QSpecialIntegerBitfield &operator<<=(T i) { return (*this = (T(*this) << i)); } -}; - -template -using QLEIntegerBitfield = QSpecialIntegerBitfield, pos, width>; - -template -using QBEIntegerBitfield = QSpecialIntegerBitfield, pos, width>; - -template -using qint32_le_bitfield = QLEIntegerBitfield; -template -using quint32_le_bitfield = QLEIntegerBitfield; -template -using qint32_be_bitfield = QBEIntegerBitfield; -template -using quint32_be_bitfield = QBEIntegerBitfield; - enum class QSpecialIntegerBitfieldInitializer {}; constexpr QSpecialIntegerBitfieldInitializer QSpecialIntegerBitfieldZero{}; diff --git a/tests/auto/corelib/global/qtendian/tst_qtendian.cpp b/tests/auto/corelib/global/qtendian/tst_qtendian.cpp index e688768b74..401367ecaa 100644 --- a/tests/auto/corelib/global/qtendian/tst_qtendian.cpp +++ b/tests/auto/corelib/global/qtendian/tst_qtendian.cpp @@ -35,8 +35,6 @@ private slots: void endianIntegers_data(); void endianIntegers(); - void endianBitfields(); - void endianBitfieldUnions_data(); void endianBitfieldUnions(); }; @@ -344,33 +342,6 @@ void tst_QtEndian::endianIntegers() #endif } -void tst_QtEndian::endianBitfields() -{ - union { - quint32_be_bitfield<21, 11> upper; - quint32_be_bitfield<10, 11> lower; - qint32_be_bitfield<0, 10> bottom; - } u; - - u.upper = 200; - QCOMPARE(u.upper, 200U); - u.lower = 1000; - u.bottom = -8; - QCOMPARE(u.lower, 1000U); - QCOMPARE(u.upper, 200U); - - u.lower += u.upper; - QCOMPARE(u.upper, 200U); - QCOMPARE(u.lower, 1200U); - - u.upper = 65536 + 7; - u.lower = 65535; - QCOMPARE(u.lower, 65535U & ((1<<11) - 1)); - QCOMPARE(u.upper, 7U); - - QCOMPARE(u.bottom, -8); -} - template typename Union, template typename Member> void testBitfieldUnion() {