diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index bd65c0ecab3..95a1d9160a6 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -315,16 +315,17 @@ namespace QTest template // Fallback; for built-in types debug streaming must be possible inline typename std::enable_if::Value && !std::is_enum_v, char *>::type toString(const T &t) { + char *result = nullptr; #ifndef QT_NO_DEBUG_STREAM if constexpr (QTypeTraits::has_ostream_operator_v) { - return qstrdup(QDebug::toString(t).toUtf8().constData()); + result = qstrdup(QDebug::toString(t).toUtf8().constData()); } else { static_assert(!QMetaTypeId2::IsBuiltIn, "Built-in type must implement debug streaming operator " "or provide QTest::toString specialization"); } #endif - return nullptr; + return result; } template // Output QFlags of registered enumerations