Author: Zeyi Xu
Date: 2026-10-30T05:25:08Z
New Revision: e5d97237dad5111a73773a42fb45ce1f3640f998

URL: 
https://github.com/llvm/llvm-project/commit/e5d97237dad5111a73773a42fb45ce1f3640f998
DIFF: 
https://github.com/llvm/llvm-project/commit/e5d97237dad5111a73773a42fb45ce1f3640f998.diff

LOG: [clang-tidy][NFC] Move isOutOfLine matcher into utils::Matchers (#228547)

AI Usage: Assisted by Grok 4.6 (Cursor)

---------

Co-authored-by: Cursor <[email protected]>

Added: 
    

Modified: 
    
clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp
    clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
    clang-tools-extra/clang-tidy/performance/TriviallyDestructibleCheck.cpp
    clang-tools-extra/clang-tidy/utils/Matchers.h

Removed: 
    


################################################################################
diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp
 
b/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp
index 904685cb8416d0..4fdb65d7505d32 100644
--- 
a/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp
@@ -7,10 +7,12 @@
 
//===----------------------------------------------------------------------===//
 
 #include "DerivedMethodShadowingBaseMethodCheck.h"
+#include "../utils/Matchers.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 
 using namespace clang::ast_matchers;
+using namespace clang::tidy::matchers;
 
 namespace clang::tidy::bugprone {
 
@@ -77,10 +79,6 @@ AST_MATCHER(CXXMethodDecl, nameCollidesWithMethodInBase) {
   return false;
 }
 
-// Same as clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp,
-// similar matchers are used elsewhere in LLVM
-AST_MATCHER(CXXMethodDecl, isOutOfLine) { return Node.isOutOfLine(); }
-
 AST_MATCHER(CXXMethodDecl, isTemplate) {
   return Node.getDescribedFunctionTemplate() != nullptr;
 }

diff  --git a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
index 3b3e57078fb4c5..4f7c28a07bae4c 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
@@ -15,6 +15,7 @@
 #include <optional>
 
 using namespace clang::ast_matchers;
+using namespace clang::tidy::matchers;
 
 namespace clang::tidy::modernize {
 
@@ -49,8 +50,8 @@ getAllDirectBases(const CXXRecordDecl *Record) {
 /// Returns a matcher that matches member expressions where the base is
 /// the variable declared as \p Var and the accessed member is the one declared
 /// as \p Field.
-static internal::Matcher<Expr> accessToFieldInVar(const FieldDecl *Field,
-                                                  const ValueDecl *Var) {
+static ast_matchers::internal::Matcher<Expr>
+accessToFieldInVar(const FieldDecl *Field, const ValueDecl *Var) {
   return ignoringImpCasts(
       
memberExpr(hasObjectExpression(declRefExpr(to(varDecl(equalsNode(Var))))),
                  member(fieldDecl(equalsNode(Field)))));
@@ -217,10 +218,6 @@ void 
UseEqualsDefaultCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "IgnoreMacros", IgnoreMacros);
 }
 
-namespace {
-AST_MATCHER(CXXMethodDecl, isOutOfLine) { return Node.isOutOfLine(); }
-} // namespace
-
 void UseEqualsDefaultCheck::registerMatchers(MatchFinder *Finder) {
   // Skip unions/union-like classes since their constructors behave 
diff erently
   // when defaulted vs. empty.

diff  --git 
a/clang-tools-extra/clang-tidy/performance/TriviallyDestructibleCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/TriviallyDestructibleCheck.cpp
index 5088cfb7ca5035..f3034f9e9eb469 100644
--- a/clang-tools-extra/clang-tidy/performance/TriviallyDestructibleCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/TriviallyDestructibleCheck.cpp
@@ -20,12 +20,6 @@ namespace clang::tidy::performance {
 
 namespace {
 
-// We use isOutOfLine() to find out-of-line defaulted destructor definitions.
-// This is more robust than !isFirstDecl() because with C++20 modules, when a
-// class is visible through both a header include and a module import, its
-// declarations may appear multiple times in the redeclaration chain.
-AST_MATCHER(CXXMethodDecl, isOutOfLine) { return Node.isOutOfLine(); }
-
 AST_MATCHER_P(CXXRecordDecl, hasBase, Matcher<QualType>, InnerMatcher) {
   return llvm::any_of(Node.bases(), [&](const CXXBaseSpecifier &BaseSpec) {
     return InnerMatcher.matches(BaseSpec.getType(), Finder, Builder);
@@ -34,6 +28,10 @@ AST_MATCHER_P(CXXRecordDecl, hasBase, Matcher<QualType>, 
InnerMatcher) {
 
 } // namespace
 
+// We use isOutOfLine() to find out-of-line defaulted destructor definitions.
+// This is more robust than !isFirstDecl() because with C++20 modules, when a
+// class is visible through both a header include and a module import, its
+// declarations may appear multiple times in the redeclaration chain.
 void TriviallyDestructibleCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
       cxxDestructorDecl(

diff  --git a/clang-tools-extra/clang-tidy/utils/Matchers.h 
b/clang-tools-extra/clang-tidy/utils/Matchers.h
index 33c0d18a250bd6..f16c46ff5b662c 100644
--- a/clang-tools-extra/clang-tidy/utils/Matchers.h
+++ b/clang-tools-extra/clang-tidy/utils/Matchers.h
@@ -22,6 +22,8 @@ AST_MATCHER(BinaryOperator, isRelationalOperator) {
 
 AST_MATCHER(BinaryOperator, isEqualityOperator) { return Node.isEqualityOp(); }
 
+AST_MATCHER(Decl, isOutOfLine) { return Node.isOutOfLine(); }
+
 AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
 
 AST_MATCHER(Expr, isMacroID) { return Node.getExprLoc().isMacroID(); }


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to