diff options
author | Tatiana Borisova <[email protected]> | 2024-08-27 16:55:22 +0200 |
---|---|---|
committer | Tatiana Borisova <[email protected]> | 2024-09-10 16:23:07 +0000 |
commit | 70e92f49c380e2237011f7bf39bfd0c724f0c160 (patch) | |
tree | 9387d1c17f9f6a31dcebb467732121336c082f46 | |
parent | 24424fa9390534a7b2fea5406bde2e827cc418a2 (diff) |
qCompare: fix 'sign-compare' compilation warnings
- It seems, clang-tidy doesn't detect 'sign-comparison' problems in qtestlib templates. But it is being detected on compilation time.
The cmp_<> API can be used for integer types to fix that warnings.
The compilation output:
/home/qt/work/base/qt5/qtbase/src/testlib/qtestcase.h:626:34: warning:
comparison of integer expressions of different signedness:
‘const long long int’ and ‘const long unsigned int’ [-Wsign-compare]
return compare_helper(t1 == t2, "Compared values are not the same",
Task-number: QTBUG-105464
Change-Id: I00c2632ec1a8c8c2f122e0b6578b16e5b0719a9e
Reviewed-by: Edward Welbourne <[email protected]>
-rw-r--r-- | src/testlib/qtestcase.h | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index b118a2066b9..75a51992d28 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -15,6 +15,7 @@ #include <QtCore/qtemporarydir.h> #include <QtCore/qthread.h> #include <QtCore/qxpfunctional.h> +#include <QtCore/q20utility.h> #include <string.h> @@ -623,10 +624,18 @@ namespace QTest using D1 = std::decay_t<T1>; using D2 = std::decay_t<T2>; using Internal::genericToString; - return compare_helper(t1 == t2, "Compared values are not the same", - std::addressof(t1), std::addressof(t2), - genericToString<D1>, genericToString<D2>, - actual, expected, file, line); + if constexpr (QtPrivate::is_standard_or_extended_integer_type_v<T1> + && QtPrivate::is_standard_or_extended_integer_type_v<T2>) { + return compare_helper(q20::cmp_equal(t1, t2), "Compared values are not the same", + std::addressof(t1), std::addressof(t2), + genericToString<D1>, genericToString<D2>, + actual, expected, file, line); + } else { + return compare_helper(t1 == t2, "Compared values are not the same", + std::addressof(t1), std::addressof(t2), + genericToString<D1>, genericToString<D2>, + actual, expected, file, line); + } } inline bool qCompare(double const &t1, float const &t2, const char *actual, |