From 45bf8ee5749b66bc8ade6b6c8518f43b2f03ef24 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 2 May 2024 11:12:25 +0200 Subject: [PATCH] compare helpers: use is_OP etc instead of OP 0 Older GCCs are otherwise going crazy with -Wzero-as-nullptr-constant. The is_OP() functions are specifically protected against this warning. Amends fe12650e9d85ea0ed4a73f85cdbef0ddf3b67ae3. Pick-to: 6.7 Change-Id: I4895e42be382c8549c1902db6f237d29f78bbe7e Reviewed-by: Ivan Solovev --- src/corelib/global/qcomparehelpers.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/corelib/global/qcomparehelpers.h b/src/corelib/global/qcomparehelpers.h index 0e43ac296b..97c972bfa7 100644 --- a/src/corelib/global/qcomparehelpers.h +++ b/src/corelib/global/qcomparehelpers.h @@ -145,8 +145,8 @@ template constexpr auto to_Qt(In in) noexcept noexcept(noexcept(compareThreeWay(rhs, lhs))) \ { \ const auto r = compareThreeWay(rhs, lhs); \ - if (r > 0) return std::strong_ordering::less; \ - if (r < 0) return std::strong_ordering::greater; \ + if (is_gt(r)) return std::strong_ordering::less; \ + if (is_lt(r)) return std::strong_ordering::greater; \ return r; \ } @@ -157,8 +157,8 @@ template constexpr auto to_Qt(In in) noexcept noexcept(noexcept(compareThreeWay(rhs, lhs))) \ { \ const auto r = compareThreeWay(rhs, lhs); \ - if (r > 0) return std::weak_ordering::less; \ - if (r < 0) return std::weak_ordering::greater; \ + if (is_gt(r)) return std::weak_ordering::less; \ + if (is_lt(r)) return std::weak_ordering::greater; \ return r; \ } @@ -169,8 +169,8 @@ template constexpr auto to_Qt(In in) noexcept noexcept(noexcept(compareThreeWay(rhs, lhs))) \ { \ const auto r = compareThreeWay(rhs, lhs); \ - if (r > 0) return std::partial_ordering::less; \ - if (r < 0) return std::partial_ordering::greater; \ + if (is_gt(r)) return std::partial_ordering::less; \ + if (is_lt(r)) return std::partial_ordering::greater; \ return r; \ } @@ -218,19 +218,19 @@ template constexpr auto to_Qt(In in) noexcept Attributes \ friend Constexpr bool operator<(LeftType const &lhs, RightType const &rhs) \ noexcept(noexcept(compareThreeWay(lhs, rhs))) \ - { return compareThreeWay(lhs, rhs) < 0; } \ + { return is_lt(compareThreeWay(lhs, rhs)); } \ Attributes \ friend Constexpr bool operator>(LeftType const &lhs, RightType const &rhs) \ noexcept(noexcept(compareThreeWay(lhs, rhs))) \ - { return compareThreeWay(lhs, rhs) > 0; } \ + { return is_gt(compareThreeWay(lhs, rhs)); } \ Attributes \ friend Constexpr bool operator<=(LeftType const &lhs, RightType const &rhs) \ noexcept(noexcept(compareThreeWay(lhs, rhs))) \ - { return compareThreeWay(lhs, rhs) <= 0; } \ + { return is_lteq(compareThreeWay(lhs, rhs)); } \ Attributes \ friend Constexpr bool operator>=(LeftType const &lhs, RightType const &rhs) \ noexcept(noexcept(compareThreeWay(lhs, rhs))) \ - { return compareThreeWay(lhs, rhs) >= 0; } + { return is_gteq(compareThreeWay(lhs, rhs)); } #define QT_DECLARE_ORDERING_HELPER_PARTIAL(LeftType, RightType, Constexpr, Attributes) \ QT_DECLARE_ORDERING_HELPER_TEMPLATE(Qt::partial_ordering, LeftType, RightType, Constexpr, \ @@ -255,19 +255,19 @@ template constexpr auto to_Qt(In in) noexcept Attributes \ friend Constexpr bool operator<(RightType const &lhs, LeftType const &rhs) \ noexcept(noexcept(compareThreeWay(rhs, lhs))) \ - { return compareThreeWay(rhs, lhs) > 0; } \ + { return is_gt(compareThreeWay(rhs, lhs)); } \ Attributes \ friend Constexpr bool operator>(RightType const &lhs, LeftType const &rhs) \ noexcept(noexcept(compareThreeWay(rhs, lhs))) \ - { return compareThreeWay(rhs, lhs) < 0; } \ + { return is_lt(compareThreeWay(rhs, lhs)); } \ Attributes \ friend Constexpr bool operator<=(RightType const &lhs, LeftType const &rhs) \ noexcept(noexcept(compareThreeWay(rhs, lhs))) \ - { return compareThreeWay(rhs, lhs) >= 0; } \ + { return is_gteq(compareThreeWay(rhs, lhs)); } \ Attributes \ friend Constexpr bool operator>=(RightType const &lhs, LeftType const &rhs) \ noexcept(noexcept(compareThreeWay(rhs, lhs))) \ - { return compareThreeWay(rhs, lhs) <= 0; } + { return is_lteq(compareThreeWay(rhs, lhs)); } #define QT_DECLARE_REVERSED_ORDERING_HELPER_PARTIAL(LeftType, RightType, Constexpr, Attributes) \ QT_DECLARE_REVERSED_ORDERING_HELPER_TEMPLATE(Qt::partial_ordering, LeftType, RightType, \