From c9da8d946b867fb6e095cefee44388f240c28c28 Mon Sep 17 00:00:00 2001 From: Victor Chernyakin Date: Sun, 6 Jul 2025 08:32:49 -0700 Subject: [PATCH 1/3] [ASTMatchers][NFC] Replace `makeMatcher` function with CTAD --- clang-tools-extra/clang-tidy/utils/Matchers.h | 4 ++-- clang/include/clang/ASTMatchers/ASTMatchersInternal.h | 7 +------ clang/include/clang/ASTMatchers/ASTMatchersMacros.h | 8 ++++---- clang/lib/Tooling/Transformer/RewriteRule.cpp | 4 ++-- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/clang-tools-extra/clang-tidy/utils/Matchers.h b/clang-tools-extra/clang-tidy/utils/Matchers.h index 2b6d377b8fd10..a7683024d69c4 100644 --- a/clang-tools-extra/clang-tidy/utils/Matchers.h +++ b/clang-tools-extra/clang-tidy/utils/Matchers.h @@ -145,7 +145,7 @@ class MatchesAnyListedNameMatcher // qualified name will be used for matching, otherwise its name will be used. inline ::clang::ast_matchers::internal::Matcher matchesAnyListedName(llvm::ArrayRef NameList) { - return ::clang::ast_matchers::internal::makeMatcher( + return ::clang::ast_matchers::internal::Matcher( new MatchesAnyListedNameMatcher(NameList)); } @@ -188,7 +188,7 @@ class MatchesAnyListedTypeNameMatcher inline ::clang::ast_matchers::internal::Matcher matchesAnyListedTypeName(llvm::ArrayRef NameList, bool CanonicalTypes) { - return ::clang::ast_matchers::internal::makeMatcher( + return ::clang::ast_matchers::internal::Matcher( new MatchesAnyListedTypeNameMatcher(NameList, CanonicalTypes)); } inline ::clang::ast_matchers::internal::Matcher diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h index 667a044abcef1..5b092537e5e7c 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -672,12 +672,7 @@ class Matcher { DynTypedMatcher Implementation; }; // class Matcher -/// A convenient helper for creating a Matcher without specifying -/// the template type argument. -template -inline Matcher makeMatcher(MatcherInterface *Implementation) { - return Matcher(Implementation); -} +template Matcher(MatcherInterface *) -> Matcher; /// Interface that allows matchers to traverse the AST. /// FIXME: Find a better name. diff --git a/clang/include/clang/ASTMatchers/ASTMatchersMacros.h b/clang/include/clang/ASTMatchers/ASTMatchersMacros.h index f781e0a565eb3..8ac55e5bb1fc0 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchersMacros.h +++ b/clang/include/clang/ASTMatchers/ASTMatchersMacros.h @@ -106,7 +106,7 @@ }; \ } \ inline ::clang::ast_matchers::internal::Matcher DefineMatcher() { \ - return ::clang::ast_matchers::internal::makeMatcher( \ + return ::clang::ast_matchers::internal::Matcher( \ new internal::matcher_##DefineMatcher##Matcher()); \ } \ inline bool internal::matcher_##DefineMatcher##Matcher::matches( \ @@ -150,7 +150,7 @@ } \ inline ::clang::ast_matchers::internal::Matcher DefineMatcher( \ ParamType const &Param) { \ - return ::clang::ast_matchers::internal::makeMatcher( \ + return ::clang::ast_matchers::internal::Matcher( \ new internal::matcher_##DefineMatcher##OverloadId##Matcher(Param)); \ } \ typedef ::clang::ast_matchers::internal::Matcher ( \ @@ -200,7 +200,7 @@ } \ inline ::clang::ast_matchers::internal::Matcher DefineMatcher( \ ParamType1 const &Param1, ParamType2 const &Param2) { \ - return ::clang::ast_matchers::internal::makeMatcher( \ + return ::clang::ast_matchers::internal::Matcher( \ new internal::matcher_##DefineMatcher##OverloadId##Matcher(Param1, \ Param2)); \ } \ @@ -476,7 +476,7 @@ } \ inline ::clang::ast_matchers::internal::Matcher DefineMatcher( \ llvm::StringRef Param, llvm::Regex::RegexFlags RegexFlags) { \ - return ::clang::ast_matchers::internal::makeMatcher( \ + return ::clang::ast_matchers::internal::Matcher( \ new internal::matcher_##DefineMatcher##OverloadId##Matcher( \ ::clang::ast_matchers::internal::createAndVerifyRegex( \ Param, RegexFlags, #DefineMatcher))); \ diff --git a/clang/lib/Tooling/Transformer/RewriteRule.cpp b/clang/lib/Tooling/Transformer/RewriteRule.cpp index 02a1931dee673..5798a9958fe7a 100644 --- a/clang/lib/Tooling/Transformer/RewriteRule.cpp +++ b/clang/lib/Tooling/Transformer/RewriteRule.cpp @@ -258,9 +258,9 @@ template ast_matchers::internal::Matcher forEachDescendantDynamically(ast_matchers::BoundNodes Nodes, DynTypedMatcher M) { - return ast_matchers::internal::makeMatcher(new BindingsMatcher( + return ast_matchers::internal::Matcher(new BindingsMatcher( std::move(Nodes), - ast_matchers::internal::makeMatcher( + ast_matchers::internal::Matcher( new DynamicForEachDescendantMatcher(std::move(M))))); } From 3bccf78f152834fd8c4e10387503ff709fe59039 Mon Sep 17 00:00:00 2001 From: Victor Chernyakin Date: Mon, 7 Jul 2025 04:25:28 -0700 Subject: [PATCH 2/3] Deprecate instead of removing --- clang/include/clang/ASTMatchers/ASTMatchersInternal.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h index 5b092537e5e7c..624befba1cf2f 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -672,8 +672,19 @@ class Matcher { DynTypedMatcher Implementation; }; // class Matcher +// Deduction guide for Matcher. template Matcher(MatcherInterface *) -> Matcher; +// TODO: Remove in LLVM 23. +template +[[deprecated( + "makeMatcher() is deprecated and will be removed in LLVM 23. " + "Uses of it can be replaced with direct calls to Matcher's " + "constructor; with C++17's CTAD, template arguments will be deduced.")]] +inline Matcher makeMatcher(MatcherInterface *Implementation) { + return Matcher(Implementation); +} + /// Interface that allows matchers to traverse the AST. /// FIXME: Find a better name. /// From 2e0e0e49fe7e35572d80739e2b149c087b3054a3 Mon Sep 17 00:00:00 2001 From: Victor Chernyakin Date: Tue, 8 Jul 2025 11:41:19 -0700 Subject: [PATCH 3/3] Shorten message --- clang/include/clang/ASTMatchers/ASTMatchersInternal.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h index 624befba1cf2f..5df2294792552 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -678,9 +678,7 @@ template Matcher(MatcherInterface *) -> Matcher; // TODO: Remove in LLVM 23. template [[deprecated( - "makeMatcher() is deprecated and will be removed in LLVM 23. " - "Uses of it can be replaced with direct calls to Matcher's " - "constructor; with C++17's CTAD, template arguments will be deduced.")]] + "Use CTAD constructor instead, 'makeMatcher' will be removed in LLVM 23.")]] inline Matcher makeMatcher(MatcherInterface *Implementation) { return Matcher(Implementation); }