From cf5da333672516921eddb4b3ba020d39b0a169d6 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 29 Jun 2023 15:53:19 +0200 Subject: [PATCH] Silence compiler warning about unreachable code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Pick-to: 6.6 6.5 Change-Id: Iaf9ec683ceceedb00771fb0743a09dcc8f50ba3f Reviewed-by: Axel Spoerl Reviewed-by: Pavel Dubsky Reviewed-by: Mårten Nordheim Reviewed-by: Jøger Hansegård --- src/testlib/qtestcase.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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