[PATCH] D126780: [clang-tidy] `bugprone-use-after-move`: Fix handling of moves in lambda captures
Martin Böhme via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 3 00:08:39 PDT 2022
mboehme updated this revision to Diff 433972.
mboehme added a comment.
Added release notes.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D126780/new/
https://reviews.llvm.org/D126780
Files:
clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
@@ -416,6 +416,13 @@
auto lambda = [&]() { a.foo(); };
std::move(a);
}
+ {
+ A a;
+ auto lambda = [a = std::move(a)] { a.foo(); };
+ a.foo();
+ // CHECK-NOTES: [[@LINE-1]]:5: warning: 'a' used after it was moved
+ // CHECK-NOTES: [[@LINE-3]]:24: note: move occurred here
+ }
}
// Use-after-moves are detected in uninstantiated templates if the moved type
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -209,6 +209,11 @@
<clang-tidy/checks/readability-suspicious-call-argument>` when the specialization
template has an unnecessary value paramter. Removed the fix for a template.
+- Fixed a bug in :doc:`bugprone-use-after-move
+ <clang-tidy/checks/bugprone-use-after-move> where a move in a lambda capture
+ was treated as if it happened within the body of the lambda, not within the
+ function that defines the lambda.
+
Removed checks
^^^^^^^^^^^^^^
Index: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -400,7 +400,8 @@
auto CallMoveMatcher =
callExpr(callee(functionDecl(hasName("::std::move"))), argumentCountIs(1),
hasArgument(0, declRefExpr().bind("arg")),
- anyOf(hasAncestor(lambdaExpr().bind("containing-lambda")),
+ anyOf(hasAncestor(compoundStmt(
+ hasParent(lambdaExpr().bind("containing-lambda")))),
hasAncestor(functionDecl().bind("containing-func"))),
unless(inDecltypeOrTemplateArg()),
// try_emplace is a common maybe-moving function that returns a
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126780.433972.patch
Type: text/x-patch
Size: 2214 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220603/932cdec7/attachment.bin>
More information about the cfe-commits
mailing list