diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index af7c07d23e6..5cbae60ac8c 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -33,6 +33,9 @@ void _q_toHex(char *&dst, Integral value) } } +#if QT_VERSION_MAJOR == 7 +# warning Consider storing the UUID as simple bytes, not as {uint, ushort, short, array} +#endif template bool _q_fromHex(const char *&src, Integral &value) { diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h index 435b7bb572d..05974454a25 100644 --- a/src/corelib/plugin/quuid.h +++ b/src/corelib/plugin/quuid.h @@ -132,7 +132,14 @@ private: static constexpr Qt::strong_ordering compareThreeWay_helper(const QUuid &lhs, const QUuid &rhs) noexcept { -#if defined(__cpp_lib_bit_cast) && defined(QT_SUPPORTS_INT128) +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED) + if (const auto c = Qt::compareThreeWay(lhs.data1, rhs.data1); !is_eq(c)) + return c; + if (const auto c = Qt::compareThreeWay(lhs.data2, rhs.data2); !is_eq(c)) + return c; + if (const auto c = Qt::compareThreeWay(lhs.data3, rhs.data3); !is_eq(c)) + return c; +#elif defined(__cpp_lib_bit_cast) && defined(QT_SUPPORTS_INT128) quint128 lu = qFromBigEndian(std::bit_cast(lhs)); quint128 ru = qFromBigEndian(std::bit_cast(rhs)); return Qt::compareThreeWay(lu, ru); @@ -144,13 +151,12 @@ private: }; if (const auto c = Qt::compareThreeWay(make_int(lhs), make_int(rhs)); !is_eq(c)) return c; - +#endif for (unsigned i = 0; i < sizeof(lhs.data4); ++i) { if (const auto c = Qt::compareThreeWay(lhs.data4[i], rhs.data4[i]); !is_eq(c)) return c; } return Qt::strong_ordering::equal; -#endif } friend constexpr Qt::strong_ordering compareThreeWay(const QUuid &lhs, const QUuid &rhs) noexcept { diff --git a/tests/auto/corelib/plugin/quuid/tst_quuid.cpp b/tests/auto/corelib/plugin/quuid/tst_quuid.cpp index 8b75817f7d0..f1b96e625d6 100644 --- a/tests/auto/corelib/plugin/quuid/tst_quuid.cpp +++ b/tests/auto/corelib/plugin/quuid/tst_quuid.cpp @@ -465,6 +465,7 @@ void tst_QUuid::ordering_data() #define AFTER_NCS(x) ROW(minNCS, x, less) AFTER_NCS(ncs000_0000_0010); AFTER_NCS(ncs000_0000_0100); + ROW(ncs000_0000_0010, ncs000_0000_0100, less); AFTER_NCS(ncs000_0000_1000); AFTER_NCS(ncs000_0001_0000); AFTER_NCS(ncs000_0010_0000); @@ -492,6 +493,13 @@ void tst_QUuid::ordering_data() AFTER_R(ones); #undef AFTER_R #undef ROW + + // due to the way we store data1,2,3 in memory, the ordering will flip + QTest::newRow("qt7-integer-portions") + << QUuid{0x01000002, 0x0000, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0} + << QUuid{0x02000001, 0x0000, 0x0000, 0, 0, 0, 0, 0, 0, 0, 0} + << (QSysInfo::ByteOrder == QSysInfo::BigEndian || QT_VERSION_MAJOR < 7 ? + Qt::strong_ordering::less : Qt::strong_ordering::greater); } void tst_QUuid::ordering() @@ -500,6 +508,7 @@ void tst_QUuid::ordering() QFETCH(const QUuid, rhs); QFETCH(const Qt::strong_ordering, expected); + QCOMPARE(qCompareThreeWay(lhs, rhs), expected); QT_TEST_ALL_COMPARISON_OPS(lhs, rhs, expected); }