[PATCH] D119165: [clang-tidy] Add processing lambda captures at bugprone-use-after-move check

Martin Böhme via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 1 07:41:44 PDT 2022


mboehme added inline comments.
Herald added a project: All.


================
Comment at: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp:403
                hasArgument(0, declRefExpr().bind("arg")),
-               anyOf(hasAncestor(lambdaExpr().bind("containing-lambda")),
-                     hasAncestor(functionDecl().bind("containing-func"))),
----------------
mboehme wrote:
> I believe this can be done more simply.
> 
> IIUC, the root of the problem is that a std::move() in a lambda capture is being associated with the lambda, when in fact it should be associated with the function that contains the lambda.
> 
> This is because the `hasAncestor(lambdaExpr())` matches not just a `std::move` inside the body of the lambda, but also in captures.
> 
> I believe this can be solved simply by changing this line so that it only matches a `std::move` inside the body of the lambda, i.e. something like this:
> 
> ```
> hasAncestor(compoundStmt(hasParent(lambdaExpr().bind("containing-lambda"))))
> ```
> 
> This would then no longer match a `std::move` in a capture; the existing logic would instead associate it with the function that contains the lambda.
> ```
It appears that this works:

https://reviews.llvm.org/D126780


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119165/new/

https://reviews.llvm.org/D119165



More information about the cfe-commits mailing list