summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <[email protected]>2024-07-15 13:50:09 +0200
committerAllan Sandfeld Jensen <[email protected]>2024-07-18 13:55:26 +0200
commit7dd2c5f91dd62840d37c5e17cc3f1f5ad46d9366 (patch)
tree36249c7ad6128876654072766bd608e602117060
parent8448292074e72095ed177d77910abe47a24f318c (diff)
Fix source compatibility with existing toString() extensions
Pick-to: 6.8 Change-Id: I946ebf0f0fa82450105e720489c4da35a77078d8 Reviewed-by: Ivan Solovev <[email protected]> Reviewed-by: Thiago Macieira <[email protected]>
-rw-r--r--src/testlib/qtestcase.cpp12
-rw-r--r--src/testlib/qtestcase.qdoc2
-rw-r--r--src/testlib/qtesttostring.h23
3 files changed, 18 insertions, 19 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 5648fedd639..1ffe283ce92 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -3144,7 +3144,16 @@ char *QTest::toString(const volatile QObject *vo)
if (vo == nullptr)
return qstrdup("<null>");
- auto *o = const_cast<const QObject*>(vo);
+ return QTest::toString(const_cast<const QObject*>(vo));
+}
+
+/*! \internal
+*/
+char *QTest::toString(const QObject *o)
+{
+ if (o == nullptr)
+ return qstrdup("<null>");
+
const QString &name = o->objectName();
const char *className = o->metaObject()->className();
char *msg = new char[256];
@@ -3155,6 +3164,7 @@ char *QTest::toString(const volatile QObject *vo)
return msg;
}
+
/*! \fn char *QTest::toString(const QColor &color)
\internal
*/
diff --git a/src/testlib/qtestcase.qdoc b/src/testlib/qtestcase.qdoc
index 6a067c351f8..7614f67312b 100644
--- a/src/testlib/qtestcase.qdoc
+++ b/src/testlib/qtestcase.qdoc
@@ -1423,7 +1423,7 @@
*/
/*!
- \fn template<typename T, QTest::Internal::is_suitable_type_v<T> = true> char *QTest::toString(const T &value)
+ \fn template <typename T> char *QTest::toString(const T &value)
Returns a textual representation of \a value. This function is used by
\l QCOMPARE() to output verbose information in case of a test failure.
diff --git a/src/testlib/qtesttostring.h b/src/testlib/qtesttostring.h
index a1ee4f69258..d5d48bb4f4e 100644
--- a/src/testlib/qtesttostring.h
+++ b/src/testlib/qtesttostring.h
@@ -81,19 +81,6 @@ inline typename std::enable_if<!QtPrivate::IsQEnumHelper<F>::Value, char*>::type
return msg;
}
-template <typename T>
-constexpr bool is_suitable_type_helper_v = std::disjunction_v<std::is_same<T, char>,
- std::is_same<T, void>,
- std::is_same<T, QObject>
- >;
-
-template <typename T>
-using is_suitable_type_v =
- std::enable_if_t<!(std::is_pointer_v<T>
- && is_suitable_type_helper_v<
- std::remove_const_t<std::remove_pointer_t<T>>>),
- bool>;
-
} // namespace Internal
Q_TESTLIB_EXPORT bool compare_string_helper(const char *t1, const char *t2, const char *actual,
@@ -102,11 +89,8 @@ Q_TESTLIB_EXPORT char *formatString(const char *prefix, const char *suffix, size
Q_TESTLIB_EXPORT char *toHexRepresentation(const char *ba, qsizetype length);
Q_TESTLIB_EXPORT char *toPrettyCString(const char *unicode, qsizetype length);
Q_TESTLIB_EXPORT char *toPrettyUnicode(QStringView string);
-Q_TESTLIB_EXPORT char *toString(const char *);
-Q_TESTLIB_EXPORT char *toString(const volatile void *);
-Q_TESTLIB_EXPORT char *toString(const volatile QObject *);
-template<typename T, Internal::is_suitable_type_v<T> = true>
+template <typename T>
inline char *toString(const T &t)
{
return Internal::toString(t);
@@ -121,6 +105,11 @@ inline char *toString(const std::tuple<Types...> &tuple);
template <typename Rep, typename Period>
inline char *toString(std::chrono::duration<Rep, Period> duration);
+Q_TESTLIB_EXPORT char *toString(const char *);
+Q_TESTLIB_EXPORT char *toString(const volatile void *);
+Q_TESTLIB_EXPORT char *toString(const QObject *);
+Q_TESTLIB_EXPORT char *toString(const volatile QObject *);
+
#define QTEST_COMPARE_DECL(KLASS)\
template<> Q_TESTLIB_EXPORT char *toString<KLASS >(const KLASS &);
#ifndef Q_QDOC