[clang-tools-extra] [clang-tidy] Prevent false-positive in presence of derived-to-base cast in bugprone.use-after-move (PR #189638)
Zeyi Xu via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 1 21:33:36 PDT 2026
================
@@ -401,9 +411,11 @@ void UseAfterMoveFinder::getDeclRefs(
}
};
- auto DeclRefMatcher = declRefExpr(hasDeclaration(equalsNode(MovedVariable)),
- unless(inDecltypeOrTemplateArg()))
- .bind("declref");
+ auto DeclRefMatcher =
+ declRefExpr(hasDeclaration(equalsNode(MovedVariable)),
+ unless(inDecltypeOrTemplateArg()),
+ optionally(hasParent(memberExpr().bind("member-expr"))))
----------------
zeyi2 wrote:
I think there is a FP, repro:
```c++
#include <utility>
struct A { int a; };
struct B { int b; };
struct C : A, B {
C(C&& other) : A(std::move(other)) { other.b; }
};
```
clang-tidy gives:
```
2 warnings generated.
/tmp/foo.cpp:5:40: warning: 'other' used after it was moved [bugprone-use-after-move]
5 | C(C&& other) : A(std::move(other)) { other.b; }
| ^
/tmp/foo.cpp:5:18: note: move occurred here
5 | C(C&& other) : A(std::move(other)) { other.b; }
| ^
Suppressed 1 warnings (1 with check filters).
```
https://github.com/llvm/llvm-project/pull/189638
More information about the cfe-commits
mailing list