From 405244fe301ac18d20aae245ba2faafaec74e453 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sun, 22 Nov 2020 18:25:44 +0100 Subject: Fix QVariant/QMetaType::compare APIs std::optional is the wrong datatype to use for compare. First and foremost, it can't be used in the idiomatic form of auto r = a.compare(b); if (r < 0) ~~~ // a is less than b if (r > 0) ~~~ // a is greater than b which we *already* feature in Qt (QString, QByteArray). Also, std::optional (explicitly) converts to bool, which is a trap, because the result of the comparison can be accidentally tested as a bool: if (a.compare(b)) ~~~ // oops! does NOT mean a API, and use that. This commits just adds the necessary parts for compare() (i.e. partial ordering), the rest of (classes, functions, conversions) can be added to 6.1. Change-Id: I2b5522da47854da39f79993e1207fad033786f00 Reviewed-by: Volker Hilsheimer (cherry picked from commit 3e59c97c3453926fc66479d9ceca03901df55f90) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp') diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 5a4ade5e47..b49f770919 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -2576,17 +2576,17 @@ void tst_QMetaType::compareCustomEqualOnlyType() // check QMetaType::compare works/doesn't crash for equals only comparators auto cmp = type.compare(variant50.constData(), variant50.constData()); - QVERIFY(!cmp); + QCOMPARE(cmp, QPartialOrdering::Unordered); bool equals = type.equals(variant50.constData(), variant50.constData()); QVERIFY(equals); cmp = type.compare(variant100.constData(), variant100x.constData()); - QVERIFY(!cmp); + QCOMPARE(cmp, QPartialOrdering::Unordered); equals = type.equals(variant100.constData(), variant100x.constData()); QVERIFY(equals); cmp = type.compare(variant50.constData(), variant100.constData()); - QVERIFY(!cmp); + QCOMPARE(cmp, QPartialOrdering::Unordered); equals = type.equals(variant50.constData(), variant100.constData()); QVERIFY(!equals); -- cgit v1.2.3