aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
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 /tests/auto
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 'tests/auto')
-rw-r--r--tests/auto/qml/qjsprimitivevalue/tst_qjsprimitivevalue.cpp6
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp3
-rw-r--r--tests/auto/qml/qqmllanguage/testtypes.h3
3 files changed, 4 insertions, 8 deletions
diff --git a/tests/auto/qml/qjsprimitivevalue/tst_qjsprimitivevalue.cpp b/tests/auto/qml/qjsprimitivevalue/tst_qjsprimitivevalue.cpp
index ea17eeae89..0c46fc9f6b 100644
--- a/tests/auto/qml/qjsprimitivevalue/tst_qjsprimitivevalue.cpp
+++ b/tests/auto/qml/qjsprimitivevalue/tst_qjsprimitivevalue.cpp
@@ -97,8 +97,7 @@ QString toString(BinaryOperator op) {
case Mod: return "%";
}
- Q_UNREACHABLE();
- return QString();
+ Q_UNREACHABLE_RETURN(QString());
}
template<typename Result>
@@ -239,8 +238,7 @@ QString toString(UnaryOperator op) {
return "--";
}
- Q_UNREACHABLE();
- return QString();
+ Q_UNREACHABLE_RETURN(QString());
}
template<typename Result, UnaryOperator Operator>
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 3d942648fd..1a0d211989 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -2624,8 +2624,7 @@ double jsEval(double arg1, double arg2, const QString &op, QJSEngine *engine)
return evalBinaryConst(u"<<"_s);
qDebug() << op;
- Q_UNREACHABLE();
- return 0;
+ Q_UNREACHABLE_RETURN(0);
}
void tst_QmlCppCodegen::mathOperations()
diff --git a/tests/auto/qml/qqmllanguage/testtypes.h b/tests/auto/qml/qqmllanguage/testtypes.h
index 060c867a27..9ba5132bb4 100644
--- a/tests/auto/qml/qqmllanguage/testtypes.h
+++ b/tests/auto/qml/qqmllanguage/testtypes.h
@@ -1818,8 +1818,7 @@ public:
int c()
{
- Q_UNREACHABLE();
- return 1111;
+ Q_UNREACHABLE_RETURN(1111);
}
};