[Libreoffice-commits] core.git: compilerplugins/clang
Stephan Bergmann (via logerrit)
logerrit at kemper.freedesktop.org
Wed Apr 7 05:30:00 UTC 2021
compilerplugins/clang/casttovoid.cxx | 26 ++++++++++++++++++++++++++
compilerplugins/clang/test/casttovoid.cxx | 12 ++++++++++++
2 files changed, 38 insertions(+)
New commits:
commit 908b47604bff6415adda791ea6f43e43c0b1443a
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Tue Apr 6 21:04:48 2021 +0200
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Wed Apr 7 07:29:20 2021 +0200
loplugin:casttovoid: Fix VisitReturnStmt in lambda bodies
...as caused the
assert(!returnTypes_.empty());
in VisitReturnStmt to hit for the return statement in the permutation2D lambda
body (which does not happen to be nested within any other function declaration)
in patch sets 1 and 2 of <https://gerrit.libreoffice.org/c/core/+/113522>
"Compute permutation2D at compile time".
Change-Id: Ic4aa55bef4361e40c2cd6247b5646f7b1ba82e6d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113699
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/compilerplugins/clang/casttovoid.cxx b/compilerplugins/clang/casttovoid.cxx
index e6da5b6d7445..1717fa09a516 100644
--- a/compilerplugins/clang/casttovoid.cxx
+++ b/compilerplugins/clang/casttovoid.cxx
@@ -169,6 +169,32 @@ public:
return RecursiveASTVisitor::TraverseConstructorInitializer(init);
}
+ bool TraverseLambdaExpr(LambdaExpr * expr, DataRecursionQueue * queue = nullptr) {
+ if (!shouldTraversePostOrder()) {
+ if (!WalkUpFromLambdaExpr(expr)) {
+ return false;
+ }
+ }
+ auto const n = expr->capture_size();
+ for (unsigned i = 0; i != n; ++i) {
+ auto const c = expr->capture_begin() + i;
+ if (c->isExplicit() || shouldVisitImplicitCode()) {
+ if (!TraverseLambdaCapture(expr, c, expr->capture_init_begin()[i])) {
+ return false;
+ }
+ }
+ }
+ if (!TraverseCXXRecordDecl(expr->getLambdaClass())) {
+ return false;
+ }
+ if (!queue && shouldTraversePostOrder()) {
+ if (!WalkUpFromLambdaExpr(expr)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
bool VisitDeclRefExpr(DeclRefExpr const * expr) {
if (ignoreLocation(expr)) {
return true;
diff --git a/compilerplugins/clang/test/casttovoid.cxx b/compilerplugins/clang/test/casttovoid.cxx
index 9904c8b5a3e4..c3b5eee17c96 100644
--- a/compilerplugins/clang/test/casttovoid.cxx
+++ b/compilerplugins/clang/test/casttovoid.cxx
@@ -73,6 +73,18 @@ int const & fS2_2(S2 const & s) {
return s.n; // expected-note {{first consumption is here [loplugin:casttovoid]}}
}
+// Don't trigger assert in CastToVoid::VisitReturnStmt:
+int n = [] { return 0; }();
+
+int f() {
+ int n1 = n;
+ int n2 = [](int const & n) -> int const & {
+ (void) n; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
+ return n; // expected-note {{first consumption is here [loplugin:casttovoid]}}
+ }(n1);
+ return n2;
+}
+
int main() {
int n1 = 0;
(void) n1; // expected-error {{unnecessary cast to void [loplugin:casttovoid]}}
More information about the Libreoffice-commits
mailing list