compilerplugins/clang/casttovoid.cxx | 26 ++++++++++++++++++++++++++ compilerplugins/clang/test/casttovoid.cxx | 12 ++++++++++++ 2 files changed, 38 insertions(+)
New commits: commit 908b47604bff6415adda791ea6f43e43c0b1443a Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Tue Apr 6 21:04:48 2021 +0200 Commit: Stephan Bergmann <sberg...@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 <sberg...@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]}} _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits