diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index eee179ffa14..d731f371e75 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -832,7 +832,7 @@ QByteArray qUncompress(const uchar* data, qsizetype nbytes) \reentrant \compares strong - \compareswith strong {const char *} QByteArrayView + \compareswith strong {const char *} \endcompareswith \compareswith strong QChar char16_t QString QStringView QLatin1StringView \ QUtf8StringView diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index a8b456a73ef..cb445788f45 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -564,7 +564,6 @@ private: return Qt::compareThreeWay(res, 0); } Q_DECLARE_STRONGLY_ORDERED(QByteArray) - Q_DECLARE_STRONGLY_ORDERED(QByteArray, QByteArrayView) Q_DECLARE_STRONGLY_ORDERED(QByteArray, const char *) #if defined(__GLIBCXX__) && defined(__cpp_lib_three_way_comparison) // libstdc++ has a bug [0] when `operator const void *()` is preferred over diff --git a/src/corelib/text/qbytearrayview.h b/src/corelib/text/qbytearrayview.h index 568b69dbb3f..4f40fd12097 100644 --- a/src/corelib/text/qbytearrayview.h +++ b/src/corelib/text/qbytearrayview.h @@ -366,13 +366,6 @@ private: } Q_DECLARE_STRONGLY_ORDERED(QByteArrayView) - friend bool comparesEqual(const QByteArrayView &lhs, const char *rhs) noexcept - { return comparesEqual(lhs, QByteArrayView(rhs)); } - friend Qt::strong_ordering - compareThreeWay(const QByteArrayView &lhs, const char *rhs) noexcept - { return compareThreeWay(lhs, QByteArrayView(rhs)); } - Q_DECLARE_STRONGLY_ORDERED(QByteArrayView, const char *) - // defined in qstring.cpp friend Q_CORE_EXPORT bool comparesEqual(const QByteArrayView &lhs, const QChar &rhs) noexcept; diff --git a/src/corelib/text/qbytearrayview.qdoc b/src/corelib/text/qbytearrayview.qdoc index 108fa0cd59a..36d5743d61a 100644 --- a/src/corelib/text/qbytearrayview.qdoc +++ b/src/corelib/text/qbytearrayview.qdoc @@ -15,8 +15,6 @@ \reentrant \compares strong - \compareswith strong QByteArray {const char *} - \endcompareswith \compareswith strong QString QStringView QUtf8StringView QLatin1StringView \ QChar char16_t When comparing with string and Unicode character types, the content is diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp index ad32c52ad78..0b2aaa8281e 100644 --- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -123,7 +123,7 @@ private: // void compare_data(bool hasConceptOfNullAndEmpty=true); - template + template void compare_impl() const; private Q_SLOTS: @@ -184,6 +184,8 @@ private Q_SLOTS: void compare_QString_QByteArrayView() { compare_impl(); } void compare_QString_const_char_star_data() { compare_data(); } void compare_QString_const_char_star() { compare_impl(); } + void compare_QString_std_u16_string_view_data() { compare_data(); } + void compare_QString_std_u16_string_view() { compare_impl(); } void compare_QStringView_QChar_data() { compare_data(false); } void compare_QStringView_QChar() { compare_impl(); } @@ -203,6 +205,8 @@ private Q_SLOTS: void compare_QStringView_QByteArrayView() { compare_impl(); } void compare_QStringView_const_char_star_data() { compare_data(); } void compare_QStringView_const_char_star() { compare_impl(); } + void compare_QStringView_std_u16_string_data() { compare_data(); } + void compare_QStringView_std_u16_string() { compare_impl(); } void compare_QUtf8StringView_QChar_data() { compare_data(false); } void compare_QUtf8StringView_QChar() { compare_impl(); } @@ -260,6 +264,13 @@ private Q_SLOTS: void compare_QByteArray_QByteArrayView() { compare_impl(); } void compare_QByteArray_const_char_star_data() { compare_data(); } void compare_QByteArray_const_char_star() { compare_impl(); } + void compare_QByteArray_std_string_view_data() { compare_data(); } + void compare_QByteArray_std_string_view() + { +#ifdef QT_BYTEARRAY_CONVERTS_TO_STD_STRING_VIEW + compare_impl(); +#endif + } void compare_QByteArrayView_QChar_data() { compare_data(false); } void compare_QByteArrayView_QChar() { compare_impl(); } @@ -279,6 +290,8 @@ private Q_SLOTS: void compare_QByteArrayView_QByteArrayView() { compare_impl(); } void compare_QByteArrayView_const_char_star_data() { compare_data(); } void compare_QByteArrayView_const_char_star() { compare_impl(); } + void compare_QByteArrayView_std_string_data() { compare_data(); } + void compare_QByteArrayView_std_string() { compare_impl(); } void compare_const_char_star_QChar_data() { compare_data(false); } void compare_const_char_star_QChar() { compare_impl(); } @@ -1630,6 +1643,13 @@ MAKE(QUtf8StringView) { return u8; } MAKE(QAnyStringViewUsingL1) { return {QAnyStringView{l1}}; } MAKE(QAnyStringViewUsingU8) { return {QAnyStringView{u8}}; } MAKE(QAnyStringViewUsingU16) { return {QAnyStringView{sv}}; } +MAKE(std::string) { return u8.toStdString(); } +#ifdef QT_BYTEARRAY_CONVERTS_TO_STD_STRING_VIEW +MAKE(std::string_view) { return u8; } +#else +MAKE(std::string_view) { return std::string_view(u8.data(), size_t(u8.size())); } +#endif +MAKE(std::u16string_view) { return sv; } #undef MAKE // Some types have ASCII-only case-insensitive compare, but are handled as containing @@ -1642,7 +1662,7 @@ template <> constexpr bool is_bytearray_like_v = true; template constexpr bool has_nothrow_member_compare_v = is_bytearray_like_v == is_bytearray_like_v; -template +template void tst_QStringApiSymmetry::compare_impl() const { QFETCH(QStringView, lhsUnicode); @@ -1686,11 +1706,14 @@ void tst_QStringApiSymmetry::compare_impl() const CHECK(<=); CHECK(>=); #undef CHECK - // Test that all string-like types implemente compareThreeWay() as a friend - // function. - const Qt::strong_ordering expectedOrdering = - Qt::compareThreeWay(caseSensitiveCompareResult, 0); - QCOMPARE_EQ(qCompareThreeWay(lhs, rhs), expectedOrdering); + + if constexpr (CheckCompareThreeWay) { + // Test that all string-like types implemente compareThreeWay() as a friend + // function. + const Qt::strong_ordering expectedOrdering = + Qt::compareThreeWay(caseSensitiveCompareResult, 0); + QCOMPARE_EQ(qCompareThreeWay(lhs, rhs), expectedOrdering); + } } template