qt5base-lts/tests/auto
Giuseppe D'Angelo 5560723e9d QCOMPARE: restore compatibility with braced-init-lists
a611a9f537 (in Qt 5) added support for
mixed-type comparisons through QCOMPARE. That commit added a new
overload for qCompare taking two types, T1 and T2; but it also left the
same-type qCompare(T, T) overload around, guarded by a Qt 6 version
check.

The mixed-type version is however not a generalization of the same-type
one, because it won't work if one of the arguments doesn't participate
in FTAD. Case in point: braced-init-lists. In Qt 5 this worked:

 QCOMPARE(some_container, {42});

but in Qt 6 it does not work any more. The mixed-type overload fails
deduction (can't deduce T2); in Qt 5 the same-type overload deduced
T=SomeContainer, and {42} was used to select a constructor for
SomeContainer.

--

There's a partial, straightforward workaround for this: default T2 to
T1 in the mized-type overload. In that case T2 has a "fallback" if it
cannot be deduced. This is partial because of course doesn't address
the case in which T1 cannot be deduced, but I don't think that is
common at all.

QList is special here, because it has qCompare overloads that makes it
comparable with arrays, initializer lists and more. I don't like that
very much -- we should probably have a qCompare(input_range,
input_range) overload, but that's an exercise for C++20.

Change-Id: I344ba33167829984978cd8d649a1904349a9edab
Pick-to: 6.5 6.6
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-07-07 12:20:50 +02:00
..
bic/data Add binary compatibility file built against 6.5.0 2023-04-19 15:40:36 +00:00
cmake Fix handling of QT_PATH_ANDROID_ABI_xxxx in android multi-abi tests 2023-07-04 16:53:16 +02:00
concurrent CMake: Make qtbase tests standalone projects 2023-07-05 15:09:32 +02:00
corelib QAnyStringView: add QDebug stream operator 2023-07-06 02:18:38 +00:00
dbus Fix spelling of D-Bus in the source code 2023-07-06 21:51:29 +02:00
gui CMake: Make gui tests standalone projects 2023-07-05 15:09:32 +02:00
guiapplauncher Move Weather Anchor Layout example to manual tests 2023-03-02 05:55:57 +01:00
network Update public suffix list 2023-07-06 17:53:11 +02:00
opengl tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
other CMake: Make qtbase tests standalone projects 2023-07-05 15:09:32 +02:00
printsupport CMake: Make qtbase tests standalone projects 2023-07-05 15:09:32 +02:00
shared tests: remove PlatformInputContext::filterEvent() 2023-01-18 13:21:06 +01:00
sql CMake: Make qtbase tests standalone projects 2023-07-05 15:09:32 +02:00
testlib QCOMPARE: restore compatibility with braced-init-lists 2023-07-07 12:20:50 +02:00
tools qdbusxml2cpp: Improve error reporting 2023-07-06 21:51:25 +02:00
wasm CMake: Make qtbase tests standalone projects 2023-07-05 15:09:32 +02:00
widgets QDialogButtonBox - Update focus chain when buttons show or hide 2023-07-06 08:41:04 +02:00
xml CMake: Make qtbase tests standalone projects 2023-07-05 15:09:32 +02:00
CMakeLists.txt tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
network-settings.h Use SPDX license identifiers 2022-05-16 16:37:38 +02:00