[PATCH] D126853: [clang-tidy] `bugprone-use-after-move`: Don't warn on self-moves.
Martin Böhme via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 1 21:52:15 PDT 2022
mboehme created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D126853
Files:
clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
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
@@ -152,6 +152,13 @@
// CHECK-NOTES: [[@LINE-3]]:15: note: move occurred here
}
+// Don't flag a move-to-self.
+void selfMove() {
+ A a;
+ a = std::move(a);
+ a.foo();
+}
+
// A warning should only be emitted for one use-after-move.
void onlyFlagOneUseAfterMove() {
A a;
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
@@ -158,9 +158,12 @@
// Ignore all reinitializations where the move potentially comes after the
// reinit.
+ // If `Reinit` is identical to `MovingCall`, we're looking at a move-to-self
+ // (e.g. `a = std::move(a)`). Count these as reinitializations.
llvm::SmallVector<const Stmt *, 1> ReinitsToDelete;
for (const Stmt *Reinit : Reinits) {
- if (MovingCall && Sequence->potentiallyAfter(MovingCall, Reinit))
+ if (MovingCall && Reinit != MovingCall &&
+ Sequence->potentiallyAfter(MovingCall, Reinit))
ReinitsToDelete.push_back(Reinit);
}
for (const Stmt *Reinit : ReinitsToDelete) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126853.433650.patch
Type: text/x-patch
Size: 1471 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220602/299841e8/attachment.bin>
More information about the cfe-commits
mailing list