summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/global/qcompare
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-11-16 07:47:14 +0100
committerIvan Solovev <ivan.solovev@qt.io>2023-11-27 18:34:10 +0100
commit4b6f757020382ed157bf6beb572549f05e881359 (patch)
treed0f8d0c47ec2b33e2a8be96ac66506c78fb87f2d /tests/auto/corelib/global/qcompare
parentc8cd9017f6c9696d79c3e7b7f0b71748839c263f (diff)
Make Qt::partial_ordering binary-compatible to std::partial_ordering
In particular, match the value of ::unordered to each std library implementation. Legal disclaimer: The values were provided to this author in a comment on QTBUG-118913. This author hereby confirms he didn't look at any of the implementations himself. The stdlib detection macros are taken from existing code in qcompilerdetection.h. I didn't succeed in googling a corresponding marker for MSSTL, and I didn't look at the implementation or Boost.Config to find one, so this patch just assumes MSSTL as a fall-back, which is probably wrong, since we may still have Dinkumware and RougeWave STLs to deal with on embedded platforms. Add tests to ensure the values are the same on all platforms. To maximize coverage, rename qcompare.qdoc to qcompare.cpp and add a bunch of compile-time tests there. These depend in part on bit_cast, which we cannot depend on, so tst_qcompare contains the same tests using memcpy. Fixes: QTBUG-118913 Change-Id: I46c922c8e3ea37d7c01a71361c7a689340f9047d Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'tests/auto/corelib/global/qcompare')
-rw-r--r--tests/auto/corelib/global/qcompare/tst_qcompare.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/corelib/global/qcompare/tst_qcompare.cpp b/tests/auto/corelib/global/qcompare/tst_qcompare.cpp
index f0bba8b3ce..7561fbdc38 100644
--- a/tests/auto/corelib/global/qcompare/tst_qcompare.cpp
+++ b/tests/auto/corelib/global/qcompare/tst_qcompare.cpp
@@ -13,6 +13,7 @@ class tst_QCompare: public QObject
Q_OBJECT
private slots:
void legacyPartialOrdering();
+ void stdQtBinaryCompatibility();
void partialOrdering();
void weakOrdering();
void strongOrdering();
@@ -130,6 +131,44 @@ void tst_QCompare::legacyPartialOrdering()
static_assert(!(0 >= QPartialOrdering::Greater));
}
+void tst_QCompare::stdQtBinaryCompatibility()
+{
+#ifndef __cpp_lib_three_way_comparison
+ QSKIP("This test requires C++20 three-way-comparison support enabled in the stdlib.");
+#else
+ QCOMPARE_EQ(sizeof(std::partial_ordering), 1U);
+ QCOMPARE_EQ(sizeof( Qt::partial_ordering), 1U);
+ QCOMPARE_EQ(sizeof(std:: weak_ordering), 1U);
+ QCOMPARE_EQ(sizeof( Qt:: weak_ordering), 1U);
+ QCOMPARE_EQ(sizeof(std:: strong_ordering), 1U);
+ QCOMPARE_EQ(sizeof( Qt:: strong_ordering), 1U);
+
+ auto valueOf = [](auto obj) {
+ typename QIntegerForSizeof<decltype(obj)>::Unsigned value;
+ memcpy(&value, &obj, sizeof(obj));
+ return value;
+ };
+#define CHECK(type, flag) \
+ QCOMPARE_EQ(valueOf( Qt:: type ## _ordering :: flag), \
+ valueOf(std:: type ## _ordering :: flag)) \
+ /* end */
+ CHECK(partial, unordered);
+ CHECK(partial, less);
+ CHECK(partial, greater);
+ CHECK(partial, equivalent);
+
+ CHECK(weak, less);
+ CHECK(weak, greater);
+ CHECK(weak, equivalent);
+
+ CHECK(strong, less);
+ CHECK(strong, greater);
+ CHECK(strong, equivalent);
+ CHECK(strong, equal);
+#undef CHECK
+#endif //__cpp_lib_three_way_comparison
+}
+
void tst_QCompare::partialOrdering()
{
static_assert(Qt::partial_ordering::unordered == Qt::partial_ordering::unordered);