Skip to content

Commit

Permalink
QCompare: add more relational operator overloads
Browse files Browse the repository at this point in the history
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.8 6.7
Fixes: QTBUG-126541
Task-number: QTQAINFRA-6203
Reviewed-by: Tatiana Borisova <[email protected]>
Reviewed-by: Khem Raj <[email protected]>
Reviewed-by: Ivan Solovev <[email protected]>
  • Loading branch information
dangelog committed Jul 22, 2024
1 parent df3c9f3 commit b892b39
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/corelib/global/qcompare.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,30 @@ class partial_ordering

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:
Expand Down

0 comments on commit b892b39

Please sign in to comment.