diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2021-04-06 21:04:48 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2021-04-07 07:29:20 +0200 |
commit | 908b47604bff6415adda791ea6f43e43c0b1443a (patch) | |
tree | 26ccf744dbb4f99a19b3a9cea0e13226fa866e48 /compilerplugins | |
parent | 3092322bb83998397b09d3f34b6d04b5e5c1da50 (diff) |
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@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/casttovoid.cxx | 26 | ||||
-rw-r--r-- | compilerplugins/clang/test/casttovoid.cxx | 12 |
2 files changed, 38 insertions, 0 deletions
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]}} |