From e358eb3bab2a613a19087b7808e02e8058e2aff4 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 21 Jun 2024 20:58:56 +0200 Subject: [PATCH] QCompare: add more relational operator overloads libc++ has a "poisoned" set of relational operator overloads for the standard category types. A call like std::strong_ordering::equivalent == Qt::partial_ordering::equivalent fails to compile, despite the presence of operator==(std::partial_ordering, Qt::partial_ordering) This is viable after converting strong_ordering. But strong_ordering itself defines a operator==(std::strong_ordering, CmpZero) where CmpZero is poisoned and accepts Qt::partial_ordering, making the call ill-formed. I'm not 100% sure if libc++ is right here (cf. the linked upstream bug report for some ruminations). We can work around this issue by adding sufficient additional overloads to Qt::partial_ordering and be a perfect match. For some reason this was already the case for the other Qt's comparison types. Notes: 1) I didn't test this. Only libc++-trunk defined the necessary C++ feature macros to trigger the problem; I made a synthetic testcase and it worked. 2) I'm not sure why these operators are defined symmetrically instead of relying on C++20's reversed operators, but I'll follow the pre-existing ones. Change-Id: I0937f40b7e685026d4677e7918948d47d2b7cec6 Pick-to: 6.7 Fixes: QTBUG-126541 Task-number: QTQAINFRA-6203 Reviewed-by: Tatiana Borisova Reviewed-by: Khem Raj Reviewed-by: Ivan Solovev (cherry picked from commit b892b39a7a6c50eb5bbf03f0c9f01bdd07756f13) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/global/qcompare.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/corelib/global/qcompare.h b/src/corelib/global/qcompare.h index fb5a40f0529..410605455b8 100644 --- a/src/corelib/global/qcompare.h +++ b/src/corelib/global/qcompare.h @@ -183,6 +183,30 @@ public: friend constexpr bool operator!=(std::partial_ordering lhs, partial_ordering rhs) noexcept { return lhs != static_cast(rhs); } + + friend constexpr bool operator==(partial_ordering lhs, std::strong_ordering rhs) noexcept + { return static_cast(lhs) == rhs; } + + friend constexpr bool operator!=(partial_ordering lhs, std::strong_ordering rhs) noexcept + { return static_cast(lhs) != rhs; } + + friend constexpr bool operator==(std::strong_ordering lhs, partial_ordering rhs) noexcept + { return lhs == static_cast(rhs); } + + friend constexpr bool operator!=(std::strong_ordering lhs, partial_ordering rhs) noexcept + { return lhs != static_cast(rhs); } + + friend constexpr bool operator==(partial_ordering lhs, std::weak_ordering rhs) noexcept + { return static_cast(lhs) == rhs; } + + friend constexpr bool operator!=(partial_ordering lhs, std::weak_ordering rhs) noexcept + { return static_cast(lhs) != rhs; } + + friend constexpr bool operator==(std::weak_ordering lhs, partial_ordering rhs) noexcept + { return lhs == static_cast(rhs); } + + friend constexpr bool operator!=(std::weak_ordering lhs, partial_ordering rhs) noexcept + { return lhs != static_cast(rhs); } #endif // __cpp_lib_three_way_comparison private: