diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2024-09-04 11:21:51 +0200 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2024-09-06 15:54:52 +0000 |
| commit | a84b79df0fb8a92b17a39bbf706714e93de9d6fc (patch) | |
| tree | 215d7ee130b4a6f497c8ab346f49ffbda3cfe94b /src | |
| parent | a338f67dceed61009375a4a90a7fe32a06b443a0 (diff) | |
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
Pick-to: 6.8
Change-Id: Ie88326519673166afe8cb44267c23944b27c68d2
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'src')
| -rw-r--r-- | src/corelib/tools/qversionnumber.h | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/corelib/tools/qversionnumber.h b/src/corelib/tools/qversionnumber.h index b6cfcf7debf..90cde6f0a8d 100644 --- a/src/corelib/tools/qversionnumber.h +++ b/src/corelib/tools/qversionnumber.h @@ -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 |
