tst_qstringapisymmetry: check QString/QAnyStringView overloads w/Q_WEAK_OVERLOAD flipped

This overload set may come in handy to cushion some of the concerns
regarding replacing QString functions with QAnyStringView ones.

Overloading with a Q_WEAK_OVERLOAD QAnyStringView function requires
users to jump through hoops in order to avoid the QString overload,
but with the Q_WEAK_OVERLOAD roles reversed, the QAnyStringView
overload becomes the preferred version, relegating the QString
overload to a fall-back to facilitate sharing where it makes sense
(e.g. for QObject::setObjectName()).

Pick-to: 6.3
Change-Id: Ic65ead505beee627976a306e2d430e800540a600
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
This commit is contained in:
Marc Mutz 2022-03-03 09:27:59 +01:00
parent 400867693b
commit 1931689c7d

View File

@ -949,6 +949,14 @@ void overload_sr_a(QString &&) {}
Q_WEAK_OVERLOAD
void overload_sr_a(QAnyStringView) {}
Q_WEAK_OVERLOAD
void overload_a_s(const QString &) {}
void overload_a_s(QAnyStringView) {}
Q_WEAK_OVERLOAD
void overload_a_sr(QString &&) {}
void overload_a_sr(QAnyStringView) {}
void overload_s_v(const QString &) {}
void overload_s_v(QStringView) {}
@ -984,6 +992,20 @@ void tst_QStringApiSymmetry::overload()
overload_sr_a(CT());
}
overload_a_s(t);
overload_a_s(ct);
if constexpr (!std::is_array_v<T>) {
overload_a_s(T());
overload_a_s(CT());
}
overload_a_sr(t);
overload_a_sr(ct);
if constexpr (!std::is_array_v<T>) {
overload_a_sr(T());
overload_a_sr(CT());
}
if constexpr (std::is_convertible_v<T, QStringView> || std::is_convertible_v<T, QString>) {
overload_s_v(t);
overload_s_v(ct);