From 534241f723161ab79d9a85b2c8145d571f0d99f9 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 13 Oct 2022 23:18:06 +0200 Subject: Port to new Q_UNREACHABLE_RETURN() This is a semantic patch using ClangTidyTransformator to convert sequences of Q_UNREACHABLE() + return into Q_UNREACHABLE_RETURN(), newly added to qtbase. const std::string unr = "unr", val = "val", ret = "ret"; auto makeUnreachableReturn = cat("Q_UNREACHABLE_RETURN(", ifBound(val, cat(node(val)), cat("")), ")"); auto ignoringSwitchCases = [](auto stmt) { return anyOf(stmt, switchCase(subStmt(stmt))); }; makeRule(stmt(ignoringSwitchCases(stmt(isExpandedFromMacro("Q_UNREACHABLE")).bind(unr)), nextStmt(returnStmt(optionally(hasReturnValue(expr().bind(val)))).bind(ret))), {changeTo(node(unr), cat(makeUnreachableReturn, ";")), // TODO: why is the ; lost w/o this? changeTo(node(ret), cat(""))}, cat("use ", makeUnreachableReturn)); a.k.a qt-use-unreachable-return. subStmt() and nextStmt() are non-standard matchers. There was one false positive, suppressed it with NOLINTNEXTLINE. It's not really a false positiive, it's just that Clang sees the world in one way and if conditonal compilation (#if) differs for other compilers, Clang doesn't know better. This is an artifact of matching two consecutive statements. Change-Id: I3855b2dc8523db1ea860f72ad9818738162495c6 Reviewed-by: Qt CI Bot Reviewed-by: Fabian Kosmale --- src/qml/qml/qqml.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/qml/qml/qqml.cpp') diff --git a/src/qml/qml/qqml.cpp b/src/qml/qml/qqml.cpp index 68cf1dc130..d5e98f1805 100644 --- a/src/qml/qml/qqml.cpp +++ b/src/qml/qml/qqml.cpp @@ -1411,8 +1411,7 @@ bool AOTCompiledContext::loadScopeObjectPropertyLookup(uint index, void *target) return true; } - Q_UNREACHABLE(); - return false; + Q_UNREACHABLE_RETURN(false); } void AOTCompiledContext::initLoadScopeObjectPropertyLookup(uint index, QMetaType type) const @@ -1595,8 +1594,7 @@ bool AOTCompiledContext::getObjectLookup(uint index, QObject *object, void *targ return true; } - Q_UNREACHABLE(); - return false; + Q_UNREACHABLE_RETURN(false); } void AOTCompiledContext::initGetObjectLookup(uint index, QObject *object, QMetaType type) const @@ -1701,8 +1699,7 @@ bool AOTCompiledContext::setObjectLookup(uint index, QObject *object, void *valu return true; } - Q_UNREACHABLE(); - return false; + Q_UNREACHABLE_RETURN(false); } void AOTCompiledContext::initSetObjectLookup(uint index, QObject *object, QMetaType type) const -- cgit v1.2.3