qt5base-lts/tests/auto
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
..
cmake CMake: Change generated resources naming 2020-11-24 21:51:29 +01:00
concurrent Fix compiler warning from comparing signed to unsigned 2020-11-27 07:28:25 +00:00
corelib Fix QVariant/QMetaType::compare APIs 2020-11-30 17:16:22 +01:00
dbus QChar: make construction from integral explicit 2020-11-15 14:41:05 +01:00
gui Use QCOMPARE(,) in preference to QVERIFY(qFuzzyCompare(,)) 2020-11-27 13:26:52 +01:00
guiapplauncher Move QStateMachine from QtCore to QtScxml 2020-08-24 20:10:25 +02:00
installed_cmake
network Blacklist authenticationCacheAfterCancel on Ubuntu 20.04 2020-11-24 20:50:42 +00:00
opengl Remove tst_QGL 2020-08-28 11:43:11 +02:00
other Android: fix tst_android test 2020-11-25 21:08:10 +00:00
printsupport Fit tst_qprinterinfo in case there are printers in local network 2020-11-21 06:11:37 +01:00
shared Remove most compiler warnings about missing overrides 2020-09-11 00:20:47 +02:00
sql Cleanup remaining QVariant::Type uses in Qt Sql 2020-10-17 12:01:54 +02:00
testlib Android: exclude faulty tst_selftests 2020-11-25 23:08:09 +02:00
tools Android: exclude host tools tests for android and ios 2020-11-16 11:35:33 +00:00
widgets QHeaderView: allow un-sorting of models 2020-11-30 18:16:21 +02:00
xml QChar: make construction from integral explicit 2020-11-15 14:41:05 +01:00
.prev_CMakeLists.txt CMake: Regenerate projects 2020-09-22 19:08:53 +02:00
auto.pro Don't error out when configuring Qt on a headless system 2020-09-26 14:36:13 +02:00
CMakeLists.txt CMake: Fix building with -DQT_FEATURE_gui=OFF 2020-09-15 20:05:32 +02:00
network-settings.h Network self-test: make it work with docker/containers 2020-11-17 19:56:06 +01:00