diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-10-13 23:18:06 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-10-20 23:59:33 +0200 |
commit | 534241f723161ab79d9a85b2c8145d571f0d99f9 (patch) | |
tree | 1e130c190346202afe4dd2deb4292b180f0c9b48 /src/qml/compiler/qqmlirbuilder.cpp | |
parent | dbff59d279182e6cd35be9a7f5240e666ba02eee (diff) |
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 <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/compiler/qqmlirbuilder.cpp')
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 8ed900e9e1..fbaf34abe1 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -483,8 +483,7 @@ QString IRBuilder::signalNameFromSignalPropertyName(const QString &signalPropert } } - Q_UNREACHABLE(); - return QString(); + Q_UNREACHABLE_RETURN(QString()); } bool IRBuilder::visit(QQmlJS::AST::UiArrayMemberList *ast) @@ -803,8 +802,7 @@ private: return Pragma::FunctionSignatureBehavior; } - Q_UNREACHABLE(); - return Pragma::PragmaType(-1); + Q_UNREACHABLE_RETURN(Pragma::PragmaType(-1)); } static bool assign(Pragma *pragma, QStringView value) @@ -869,8 +867,7 @@ private: default: break; } - Q_UNREACHABLE(); - return QLatin1StringView(); + Q_UNREACHABLE_RETURN(QLatin1StringView()); } }; |