diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-02-22 15:40:43 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2017-04-21 19:58:51 +0000 |
commit | a611a9f537f1187825339c2a2214c8ec4a23680f (patch) | |
tree | 328fc4df9b633bafe0394b165c72e6cedcd65311 /src/testlib/qxmltestlogger.cpp | |
parent | 3f135dbcb931bc74741f0f23831831775b84eba3 (diff) |
QCOMPARE: allow mixed-type comparisons
There's no reason to restrict the LHS and the RHS to the same type
like it was done before. That just leads to lots of casting. or use
of QVERIFY(. == .) instead of QCOMPARE, with all the disadvantages
like no printing of the LHS and RHS values.
The rationale given in the documentation for this behavior is
incorrect. Ensuring that RHS and LHS have the same type by no means
ensures that no implicit conversions take place when calling
operator==. Proof:
QCOMPARE(QLatin1Char('a'), QLatin1Char('a'));
// instantiates
qCompare<QLatin1Char, QLatin1Char>
// but calls
operator==(QChar, QChar)
If the intent is to disable implicit conversions of the argument
types, then some serious metaprogramming magic would be needed, along
the following lines:
1. find out which op== overload is actually chosen
2. find that overload's RHS parameter type, assert it's the same as
(possibly cv-qualified) T1.
3. ditto for the LHS parameter type and T2
This is not attempted here.
Fix the inconvenience this restriction caused by simply allowing
two types.
This cannot break existing code, since we didn't actually change
anything in the qCompare() overload set. All we do is implement the
existing qCompare<T1, T2>() overload.
[ChangeLog][QtTest] QCOMPARE can now be used for mixed-type
comparisons.
Change-Id: I0413dbd3689809852413eaca22827257f1527720
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/testlib/qxmltestlogger.cpp')
0 files changed, 0 insertions, 0 deletions