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 <tatiana.borisova@qt.io>
Reviewed-by: Khem Raj <raj.khem@gmail.com>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
(cherry picked from commit b892b39a7a6c50eb5bbf03f0c9f01bdd07756f13)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Giuseppe D'Angelo 2024-06-21 20:58:56 +02:00 committed by Qt Cherry-pick Bot
parent 0e9046f20d
commit e358eb3bab

View File

@ -183,6 +183,30 @@ public:
friend constexpr bool operator!=(std::partial_ordering lhs, partial_ordering rhs) noexcept
{ return lhs != static_cast<std::partial_ordering>(rhs); }
friend constexpr bool operator==(partial_ordering lhs, std::strong_ordering rhs) noexcept
{ return static_cast<std::partial_ordering>(lhs) == rhs; }
friend constexpr bool operator!=(partial_ordering lhs, std::strong_ordering rhs) noexcept
{ return static_cast<std::partial_ordering>(lhs) != rhs; }
friend constexpr bool operator==(std::strong_ordering lhs, partial_ordering rhs) noexcept
{ return lhs == static_cast<std::partial_ordering>(rhs); }
friend constexpr bool operator!=(std::strong_ordering lhs, partial_ordering rhs) noexcept
{ return lhs != static_cast<std::partial_ordering>(rhs); }
friend constexpr bool operator==(partial_ordering lhs, std::weak_ordering rhs) noexcept
{ return static_cast<std::partial_ordering>(lhs) == rhs; }
friend constexpr bool operator!=(partial_ordering lhs, std::weak_ordering rhs) noexcept
{ return static_cast<std::partial_ordering>(lhs) != rhs; }
friend constexpr bool operator==(std::weak_ordering lhs, partial_ordering rhs) noexcept
{ return lhs == static_cast<std::partial_ordering>(rhs); }
friend constexpr bool operator!=(std::weak_ordering lhs, partial_ordering rhs) noexcept
{ return lhs != static_cast<std::partial_ordering>(rhs); }
#endif // __cpp_lib_three_way_comparison
private: