diff options
author | Marc Mutz <marc.mutz@qt.io> | 2024-01-09 09:02:53 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2024-01-12 09:38:18 +0000 |
commit | 6d005b7c570f2ad25cf2b88329a2f99ab20b8787 (patch) | |
tree | 28384896057bb9b927566f85182c22364b11bb55 | |
parent | 723ab99b1ac55c8d32a93ea80224d7ffb22f7893 (diff) |
tst_QCompareHelpers: fix narrowing warning
Warns MingW (or, in general, any GCC 13):
warning: converting to 'QtPrivate::NativeFloat16Type' {aka '_Float16'} from 'double' with greater conversion rank
See also a61d7529511c890aa595110b9320ea0bf53dd623.
Fix by using ints instead.
As a drive-by, make the variable constexpr.
Amends 4b755bc11a8eadd156c65b7474c11e3ce822c6f1.
Pick-to: 6.7
Change-Id: Ie3f3c51aa7e9323c7ba96c810d2e95247d222fd2
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
-rw-r--r-- | tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp index c0911409d7..8da320a63a 100644 --- a/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp +++ b/tests/auto/corelib/global/qcomparehelpers/tst_qcomparehelpers.cpp @@ -511,11 +511,11 @@ template <typename LeftType, typename RightType, Qt::if_floating_point<RightType> = true> void testOrderForTypes() { - LeftType lNeg{-1.0}; - LeftType lPos{1.0}; + constexpr auto lNeg = LeftType(-1); + constexpr auto lPos = LeftType( 1); - RightType rNeg{-1.0}; - RightType rPos{1.0}; + constexpr auto rNeg = RightType(-1); + constexpr auto rPos = RightType( 1); QCOMPARE_EQ(Qt::compareThreeWay(lNeg, rPos), Qt::partial_ordering::less); QCOMPARE_EQ(Qt::compareThreeWay(lPos, rNeg), Qt::partial_ordering::greater); @@ -584,8 +584,8 @@ void testOrderForTypes() IntType l0{0}; IntType l1{1}; - FloatType r0{0.0}; - FloatType r1{1.0}; + constexpr FloatType r0{0}; + constexpr FloatType r1{1}; FloatType rNaN{std::numeric_limits<FloatType>::quiet_NaN()}; QCOMPARE_EQ(Qt::compareThreeWay(l0, r1), Qt::partial_ordering::less); @@ -676,8 +676,8 @@ void tst_QCompareHelpers::builtinOrder() { // Cannot use TEST_BUILTIN here, because std::numeric_limits are not defined // for QtPrivate::NativeFloat16Type. - const QtPrivate::NativeFloat16Type smaller{1.0}; - const QtPrivate::NativeFloat16Type bigger{2.0}; + constexpr auto smaller = QtPrivate::NativeFloat16Type(1); + constexpr auto bigger = QtPrivate::NativeFloat16Type(2); // native vs native QCOMPARE_EQ(Qt::compareThreeWay(smaller, smaller), Qt::partial_ordering::equivalent); QCOMPARE_EQ(Qt::compareThreeWay(smaller, bigger), Qt::partial_ordering::less); |