[clang-tools-extra] [clang-tidy] Prevent false-positive in presence of derived-to-base cast in bugprone.use-after-move (PR #189638)

Victor Chernyakin via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 11 02:47:17 PDT 2026


================
@@ -30,6 +30,24 @@ namespace clang::tidy::bugprone {
 
 using matchers::hasUnevaluatedContext;
 
+namespace {
+AST_MATCHER_P(Expr, hasParentIgnoringParenImpCasts,
+              ast_matchers::internal::Matcher<Expr>, InnerMatcher) {
+  const Expr *E = &Node;
+  do {
+    const DynTypedNodeList Parents = Finder->getASTContext().getParents(*E);
+    if (Parents.size() != 1)
+      return false;
+    E = Parents[0].get<Expr>();
+    if (!E)
+      return false;
+  } while (isa<ImplicitCastExpr, ParenExpr>(E));
+
+  return InnerMatcher.matches(*E, Finder, Builder);
+}
+
+} // namespace
+
 namespace {
----------------
localspook wrote:

```suggestion
```

https://github.com/llvm/llvm-project/pull/189638


More information about the cfe-commits mailing list