aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-10-13 23:18:06 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-10-20 23:59:33 +0200
commit534241f723161ab79d9a85b2c8145d571f0d99f9 (patch)
tree1e130c190346202afe4dd2deb4292b180f0c9b48 /tools
parentdbff59d279182e6cd35be9a7f5240e666ba02eee (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 'tools')
-rw-r--r--tools/qmljsrootgen/main.cpp3
-rw-r--r--tools/qmlscene/main.cpp3
-rw-r--r--tools/qmltc/qmltcvisitor.cpp3
3 files changed, 3 insertions, 6 deletions
diff --git a/tools/qmljsrootgen/main.cpp b/tools/qmljsrootgen/main.cpp
index 77abd1be54..2bd54692d1 100644
--- a/tools/qmljsrootgen/main.cpp
+++ b/tools/qmljsrootgen/main.cpp
@@ -86,8 +86,7 @@ static QString findClassName(const QJSManagedValue &value)
if (QV4::ScopedValue scoped(scope, asManaged(value)); scoped->isManaged())
return scoped->managed()->vtable()->className;
- Q_UNREACHABLE();
- return QString();
+ Q_UNREACHABLE_RETURN(QString());
}
static QString buildClass(const QJSManagedValue &value, QJsonArray *classes,
diff --git a/tools/qmlscene/main.cpp b/tools/qmlscene/main.cpp
index 891b7534bd..123844ebb3 100644
--- a/tools/qmlscene/main.cpp
+++ b/tools/qmlscene/main.cpp
@@ -397,8 +397,7 @@ static QQuickWindow::TextRenderType parseTextRenderType(const QString &renderTyp
usage();
- Q_UNREACHABLE();
- return QQuickWindow::QtTextRendering;
+ Q_UNREACHABLE_RETURN(QQuickWindow::QtTextRendering);
}
int main(int argc, char ** argv)
diff --git a/tools/qmltc/qmltcvisitor.cpp b/tools/qmltc/qmltcvisitor.cpp
index c36290a360..504ccbf159 100644
--- a/tools/qmltc/qmltcvisitor.cpp
+++ b/tools/qmltc/qmltcvisitor.cpp
@@ -352,8 +352,7 @@ QQmlJSScope::ConstPtr fetchType(const QQmlJSMetaPropertyBinding &binding)
}
// coverity complains about the unreachable return below,
// some compilers; some compilers complain without it
- Q_UNREACHABLE();
- return {};
+ Q_UNREACHABLE_RETURN({});
}
template<typename Predicate>