QVersionNumber: make iterator comparison non-noexcept again

When these iterators were originally added¹, their relational
operators, following the Lakos Rule, were not marked as noexcept
because they have preconditions (lhs and rhs must come from the same
QVersionNumber object).

d292648d0bbac50388dae035dc34782accb3807f then added the noexcept,
disregarding the Lakos Rule. Until the ongoing discussion regarding
the Lakos Rule on the project mailing-list² is concluded, don't add
noexcept. We can always add it in later, but we can't remove it once
released.

Requires manually working around the missing
Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE_NON_NOEXCEPT macro that we
don't want to add if there's no other user.

¹ 2188ca2c5df6f21a953c002edbe5b2d2cc2c2d2c
² thread starting at
  https://lists.qt-project.org/pipermail/development/2024-August/045544.html

Change-Id: Ie88326519673166afe8cb44267c23944b27c68d2
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
(cherry picked from commit a84b79df0fb8a92b17a39bbf706714e93de9d6fc)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2024-09-04 11:21:51 +02:00 committed by Qt Cherry-pick Bot
parent 92d9a741c0
commit 3dc6b37bae

View File

@ -201,11 +201,35 @@ class QVersionNumber
friend class QVersionNumber;
explicit constexpr It(const QVersionNumber *vn, qsizetype idx) noexcept : v(vn), i(idx) {}
friend constexpr bool comparesEqual(const It &lhs, const It &rhs) noexcept
friend constexpr bool comparesEqual(const It &lhs, const It &rhs)
{ Q_ASSERT(lhs.v == rhs.v); return lhs.i == rhs.i; }
friend constexpr Qt::strong_ordering compareThreeWay(const It &lhs, const It &rhs) noexcept
friend constexpr Qt::strong_ordering compareThreeWay(const It &lhs, const It &rhs)
{ Q_ASSERT(lhs.v == rhs.v); return Qt::compareThreeWay(lhs.i, rhs.i); }
Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(It)
// macro variant does not exist: Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE_NON_NOEXCEPT(It)
friend constexpr bool operator==(It lhs, It rhs) {
return comparesEqual(lhs, rhs);
}
#ifdef __cpp_lib_three_way_comparison
friend constexpr std::strong_ordering operator<=>(It lhs, It rhs) {
return compareThreeWay(lhs, rhs);
}
#else
friend constexpr bool operator!=(It lhs, It rhs) {
return !operator==(lhs, rhs);
}
friend constexpr bool operator<(It lhs, It rhs) {
return is_lt(compareThreeWay(lhs, rhs));
}
friend constexpr bool operator<=(It lhs, It rhs) {
return is_lteq(compareThreeWay(lhs, rhs));
}
friend constexpr bool operator>(It lhs, It rhs) {
return is_gt(compareThreeWay(lhs, rhs));
}
friend constexpr bool operator>=(It lhs, It rhs) {
return is_gteq(compareThreeWay(lhs, rhs));
}
#endif
public:
// Rule Of Zero applies