summaryrefslogtreecommitdiffstats
path: root/src/corelib/text
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2020-08-04 16:13:13 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2020-08-04 19:52:08 +0200
commit883f2dd81f8d85d52130aece540cdf9efa3d0069 (patch)
tree832b2e8a0dda77c1707d89da94ff3b854fbd3322 /src/corelib/text
parent8a919474230d8fcbafb4a70def58bd471ab47c9c (diff)
Avoid possible ambiguities with QByteArrayView's comparison operators
QByteArrayView's comparison operators are declared in the global namespace, which can collide with the ones declared for other types that are implicitly convertible to QByteArrayView (see the example attached to the bugreport). Changing them to be hidden friends will make them visible only when at least one of the operands is a QByteArrayView, so the ambiguity will be avoided. Fixes: QTBUG-85880 Change-Id: Ic3582269d9bda9a2105336ef0f044ea619af37ba Reviewed-by: Marco Bubke <marco.bubke@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/text')
-rw-r--r--src/corelib/text/qbytearrayview.h21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/corelib/text/qbytearrayview.h b/src/corelib/text/qbytearrayview.h
index 36764abfb4..4366c37ed2 100644
--- a/src/corelib/text/qbytearrayview.h
+++ b/src/corelib/text/qbytearrayview.h
@@ -289,20 +289,25 @@ public:
[[nodiscard]] constexpr char first() const { return front(); }
[[nodiscard]] constexpr char last() const { return back(); }
+ friend inline bool operator==(QByteArrayView lhs, QByteArrayView rhs) noexcept
+ { return lhs.size() == rhs.size() && QtPrivate::compareMemory(lhs, rhs) == 0; }
+ friend inline bool operator!=(QByteArrayView lhs, QByteArrayView rhs) noexcept
+ { return !(lhs == rhs); }
+ friend inline bool operator< (QByteArrayView lhs, QByteArrayView rhs) noexcept
+ { return QtPrivate::compareMemory(lhs, rhs) < 0; }
+ friend inline bool operator<=(QByteArrayView lhs, QByteArrayView rhs) noexcept
+ { return QtPrivate::compareMemory(lhs, rhs) <= 0; }
+ friend inline bool operator> (QByteArrayView lhs, QByteArrayView rhs) noexcept
+ { return !(lhs <= rhs); }
+ friend inline bool operator>=(QByteArrayView lhs, QByteArrayView rhs) noexcept
+ { return !(lhs < rhs); }
+
private:
qsizetype m_size;
const storage_type *m_data;
};
Q_DECLARE_TYPEINFO(QByteArrayView, Q_PRIMITIVE_TYPE);
-// QByteArrayView <> QByteArrayView
-inline bool operator==(QByteArrayView lhs, QByteArrayView rhs) noexcept { return lhs.size() == rhs.size() && QtPrivate::compareMemory(lhs, rhs) == 0; }
-inline bool operator!=(QByteArrayView lhs, QByteArrayView rhs) noexcept { return !(lhs == rhs); }
-inline bool operator< (QByteArrayView lhs, QByteArrayView rhs) noexcept { return QtPrivate::compareMemory(lhs, rhs) < 0; }
-inline bool operator<=(QByteArrayView lhs, QByteArrayView rhs) noexcept { return QtPrivate::compareMemory(lhs, rhs) <= 0; }
-inline bool operator> (QByteArrayView lhs, QByteArrayView rhs) noexcept { return !(lhs <= rhs); }
-inline bool operator>=(QByteArrayView lhs, QByteArrayView rhs) noexcept { return !(lhs < rhs); }
-
template<typename QByteArrayLike,
std::enable_if_t<std::is_same_v<QByteArrayLike, QByteArray>, bool> = true>
[[nodiscard]] inline QByteArrayView qToByteArrayViewIgnoringNull(const QByteArrayLike &b) noexcept