qt6-bb10/tests/auto/corelib/kernel
Giuseppe D'Angelo 405244fe30 Fix QVariant/QMetaType::compare APIs
std::optional<int> 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<int> (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<b

Not to mention extending this to algorithms:

  auto lessThan = [](QVariant a, QVariant b) { return a.compare(b); }; // oops!
  std::ranges::sort(vectorOfVariants, lessThan);

which thankfully doesn't compile as is -- std::optional has
an *explicit* operator bool, and the Compare concept requires an
implicit conversion. However, the error the user is going to face
will be "cannot convert to bool because the operator is explicit",
which is deceiving because the fix is NOT supposed to be:

  auto lessThan = [](QVariant a, QVariant b) { return (bool)a.compare(b); }; // big oops!

Instead: backport to Qt the required subset of C++20's <compare>
API, and use that. This commits just adds the necessary parts
for compare() (i.e. partial ordering), the rest of <compare>
(classes, functions, conversions) can be added to 6.1.

Change-Id: I2b5522da47854da39f79993e1207fad033786f00
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 3e59c97c3453926fc66479d9ceca03901df55f90)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2020-11-30 17:16:22 +01:00
..
qcoreapplication Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
qdeadlinetimer Fix tst_QDeadlineTimer::stdchrono() flaky test 2020-10-27 17:43:12 +02:00
qelapsedtimer Fix tst_QDeadlineTimer::stdchrono() flaky test 2020-10-27 17:43:12 +02:00
qeventdispatcher CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qeventloop Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
qmath Add some tests for various qmath.h functions 2020-11-17 19:55:04 +01:00
qmetacontainer QSet: add missing insert-with-hint 2020-11-25 22:08:09 +01:00
qmetaenum CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qmetamethod CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qmetaobject Deprecate QVariant::Type 2020-10-23 09:58:57 +02:00
qmetaobjectbuilder QMetaObjectBuilder: remove relocatable data support 2020-11-30 17:16:21 +01:00
qmetaproperty CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qmetatype Fix QVariant/QMetaType::compare APIs 2020-11-30 17:16:22 +01:00
qmimedata CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qobject QMetaProperty::typeName: use name from metatype 2020-11-30 17:16:21 +01:00
qpointer Another round of replacing 0 with nullptr 2020-10-07 23:02:47 +02:00
qproperty QProperty: Fix notification logic for eager properties 2020-11-03 13:06:15 +01:00
qsharedmemory QSharedMemory: do not abuse QChar in a test 2020-11-08 02:13:22 +00:00
qsignalblocker CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qsignalmapper CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qsocketnotifier CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qsystemsemaphore CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qtimer Test QTimer's isSingleShot() and timerType() 2020-11-17 19:55:05 +01:00
qtranslator CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
qvariant Replace discouraged Q_MOVABLE_TYPE by Q_RELOCATABLE_TYPE 2020-11-30 17:16:21 +01:00
qwineventnotifier CMake: Regenerate projects to use new qt_internal_ API 2020-09-23 16:59:06 +02:00
.prev_CMakeLists.txt Android: blacklist a list of failing tests for android 2020-11-04 12:27:49 +02:00
CMakeLists.txt Android: blacklist a list of failing tests for android 2020-11-04 12:27:49 +02:00
kernel.pro Android: blacklist a list of failing tests for android 2020-11-04 12:27:49 +02:00