Silence compiler warning about unreachable code

The warning has been reported by users, but never observed in CI, even
though the only path that can lead to the last return statement becoming
unreachable is very common in Qt: if a QDebug stream operator exists,
then we always return early.

Nevertheless, rewrite the code to have a single return statement.

Task-number: QTBUG-112371
Fixes: QTBUG-114944
Change-Id: Iaf9ec683ceceedb00771fb0743a09dcc8f50ba3f
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: Pavel Dubsky <pavel.dubsky@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Jøger Hansegård <joger.hansegard@qt.io>
(cherry picked from commit cf5da333672516921eddb4b3ba020d39b0a169d6)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Volker Hilsheimer 2023-06-29 15:53:19 +02:00 committed by Qt Cherry-pick Bot
parent bc2ba337dc
commit 4df0132adc

View File

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