[clang] [clang-tools-extra] Move isLocal AST matcher to ASTMatchers for reusability (PR #117521)

via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 24 21:59:10 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tidy

Author: Marie Zhussupova (phychee)

<details>
<summary>Changes</summary>

Fixes #<117431>

---
Full diff: https://github.com/llvm/llvm-project/pull/117521.diff


2 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp (-3) 
- (modified) clang/include/clang/ASTMatchers/ASTMatchers.h (+5) 


``````````diff
diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 71a4cee4bdc6ef..7c159d8dd8659b 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -17,9 +17,6 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::misc {
 
 namespace {
-// FIXME: This matcher exists in some other code-review as well.
-// It should probably move to ASTMatchers.
-AST_MATCHER(VarDecl, isLocal) { return Node.isLocalVarDecl(); }
 AST_MATCHER_P(DeclStmt, containsAnyDeclaration,
               ast_matchers::internal::Matcher<Decl>, InnerMatcher) {
   return ast_matchers::internal::matchesFirstInPointerRange(
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 4bcaa953a61af2..f8388028d2ccbe 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -739,6 +739,11 @@ AST_MATCHER(FunctionDecl, isMain) {
   return Node.isMain();
 }
 
+// Matches variable declarations that represent local variables.
+AST_MATCHER(VarDecl, isLocal) { 
+    return Node.isLocalVarDecl(); 
+}
+
 /// Matches the specialized template of a specialization declaration.
 ///
 /// Given

``````````

</details>


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


More information about the cfe-commits mailing list