[clang-tools-extra] [clang-tidy] add new check: modernize-use-scoped-lock (PR #126434)

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 14 07:30:22 PDT 2025


https://github.com/HerrCai0907 requested changes to this pull request.

I try to use it. The matcher for single and multiple is unclear.
It can give more clear matcher results.
```
AST_MATCHER_P(CompoundStmt, hasMultiple, ast_matchers::internal::Matcher<Stmt>,
              InnerMatcher) {
  size_t Cnt = 0;
  for (const Stmt *Stmt : Node.body()) {
    if (InnerMatcher.matches(*Stmt, Finder, Builder))
      Cnt++;
  }
  return Cnt > 1;
}

AST_MATCHER_P(CompoundStmt, hasSingle, ast_matchers::internal::Matcher<Stmt>,
              InnerMatcher) {
  ast_matchers::internal::BoundNodesTreeBuilder Result;
  size_t Cnt = 0;
  for (const Stmt *Stmt : Node.body()) {
    ast_matchers::internal::BoundNodesTreeBuilder TB(*Builder);
    if (InnerMatcher.matches(*Stmt, Finder, &TB)) {
      Cnt++;
      Result.addMatch(TB);
    }
  }
  if (Cnt == 1) {
    *Builder = std::move(Result);
    return true;
  }
  Builder->removeBindings([](const ast_matchers::internal::BoundNodesMap &) { return true; });
  return false;
}
```

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


More information about the cfe-commits mailing list