From af5f91fdf9edc96149fd2070c2b32985c5773778 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 12 Jun 2021 13:37:21 +0200 Subject: [PATCH] tst_qstringapisymmetry: add checks for common overload sets - QString/QStringView overloads were designed to be compatible for all possible argument types, so check that it stays that way - QString/QAnyStringView overloads have several known ambiguities that we cannot and don't want to fix, because it would make QAnyStringView less versatile, but at one should at least be able to overload QString and weak-QAnyStringView. Change-Id: I5e5ae3c96060c93bfe070f6c19213328dae9c5f9 Reviewed-by: Giuseppe D'Angelo --- .../tst_qstringapisymmetry.cpp | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp index 32c2576b86..3f2838e2b7 100644 --- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -121,10 +121,54 @@ static QByteArray rowName(const QByteArray &data) return result; } +#ifdef __cpp_char8_t +# define IF_CHAR8T(x) do { x; } while (false) +#else +# define IF_CHAR8T(x) QSKIP("This test requires C++20 char8_t support enabled in the compiler.") +#endif + class tst_QStringApiSymmetry : public QObject { Q_OBJECT + // + // Overload set checks + // + +private: + template + void overload(); + +private Q_SLOTS: + void overload_char() { overload(); } + void overload_QChar() { overload(); } + void overload_char16_t() { overload(); } + void overload_QString() { overload(); } + void overload_QStringView() { overload(); } + void overload_QUtf8StringView() { overload(); } + void overload_QAnyStringView() { overload(); } + void overload_QLatin1String() { overload(); } + void overload_QByteArray() { overload(); } + void overload_const_char_star() { overload(); } + void overload_const_char8_t_star() { IF_CHAR8T(overload()); } + void overload_const_char16_t_star() { overload(); } + void overload_char_array() { overload(); } + void overload_char8_t_array() { IF_CHAR8T(overload()); } + void overload_char16_t_array() { overload(); } + void overload_QChar_array() { overload(); } + void overload_std_string() { overload(); } + void overload_std_u8string() { IF_CHAR8T(overload()); } + void overload_std_u16string() { overload(); } + void overload_QVarLengthArray_char() { overload>(); } + void overload_QVarLengthArray_char8_t() { IF_CHAR8T((overload>())); } + void overload_QVarLengthArray_char16_t() { overload>(); } + void overload_QVarLengthArray_QChar() { overload>(); } + void overload_vector_char() { overload>(); } + void overload_vector_char8_t() { IF_CHAR8T(overload>()); } + void overload_vector_char16_t() { overload>(); } + void overload_vector_QChar() { overload>(); } + +private: // // Mixed UTF-16, UTF-8, Latin-1 checks: // @@ -856,6 +900,68 @@ private Q_SLOTS: void indexOf_regexp_QStringView() { indexOf_contains_lastIndexOf_count_regexp_impl(); } }; +namespace { + +void overload_s_a(const QString &) {} +Q_WEAK_OVERLOAD +void overload_s_a(QAnyStringView) {} + +void overload_sr_a(QString &&) {} +Q_WEAK_OVERLOAD +void overload_sr_a(QAnyStringView) {} + +void overload_s_v(const QString &) {} +void overload_s_v(QStringView) {} + +void overload_sr_v(QString &&) {} +void overload_sr_v(QStringView) {} + +} // unnamed namespace + +template +void tst_QStringApiSymmetry::overload() +{ + // compile-only test: + // + // check the common overload sets defined above to be free of ambiguities + // for arguments of type T + + using CT = const T; + + T t = {}; + CT ct = {}; + + overload_s_a(t); + overload_s_a(ct); + if constexpr (!std::is_array_v) { + overload_s_a(T()); + overload_s_a(CT()); + } + + overload_sr_a(t); + overload_sr_a(ct); + if constexpr (!std::is_array_v) { + overload_sr_a(T()); + overload_sr_a(CT()); + } + + if constexpr (std::is_convertible_v || std::is_convertible_v) { + overload_s_v(t); + overload_s_v(ct); + if constexpr (!std::is_array_v) { + overload_s_v(T()); + overload_s_v(CT()); + } + + overload_sr_v(t); + overload_sr_v(ct); + if constexpr (!std::is_array_v) { + overload_sr_v(T()); + overload_sr_v(CT()); + } + } +} + void tst_QStringApiSymmetry::compare_data(bool hasConceptOfNullAndEmpty) { QTest::addColumn("lhsUnicode");