Skip to content

[ASTMatchers][NFC] Replace makeMatcher function with CTAD #147197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

localspook
Copy link

C++17's CTAD obsoletes makeMatcher (and many make* functions like it).

The deduction guide is written out explicitly to avoid -Wctad-maybe-unsupported warnings.

Copy link

github-actions bot commented Jul 6, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang-tools-extra clang-tidy labels Jul 6, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 6, 2025

@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-tidy

Author: Victor Chernyakin (localspook)

Changes

C++17's CTAD obsoletes makeMatcher (and many make* functions like it).

The deduction guide is written out explicitly to avoid -Wctad-maybe-unsupported warnings.


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

4 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/utils/Matchers.h (+2-2)
  • (modified) clang/include/clang/ASTMatchers/ASTMatchersInternal.h (+1-6)
  • (modified) clang/include/clang/ASTMatchers/ASTMatchersMacros.h (+4-4)
  • (modified) clang/lib/Tooling/Transformer/RewriteRule.cpp (+2-2)
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<NamedDecl>
 matchesAnyListedName(llvm::ArrayRef<StringRef> 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<QualType>
 matchesAnyListedTypeName(llvm::ArrayRef<StringRef> 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<QualType>
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<T> without specifying
-/// the template type argument.
-template <typename T>
-inline Matcher<T> makeMatcher(MatcherInterface<T> *Implementation) {
-  return Matcher<T>(Implementation);
-}
+template <typename T> Matcher(MatcherInterface<T> *) -> Matcher<T>;
 
 /// 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<Type> 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<Type> 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<Type> (                     \
@@ -200,7 +200,7 @@
   }                                                                            \
   inline ::clang::ast_matchers::internal::Matcher<Type> 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<Type> 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 <typename T>
 ast_matchers::internal::Matcher<T>
 forEachDescendantDynamically(ast_matchers::BoundNodes Nodes,
                              DynTypedMatcher M) {
-  return ast_matchers::internal::makeMatcher(new BindingsMatcher<T>(
+  return ast_matchers::internal::Matcher(new BindingsMatcher<T>(
       std::move(Nodes),
-      ast_matchers::internal::makeMatcher(
+      ast_matchers::internal::Matcher(
           new DynamicForEachDescendantMatcher<T>(std::move(M)))));
 }
 

@llvmbot
Copy link
Member

llvmbot commented Jul 6, 2025

@llvm/pr-subscribers-clang

Author: Victor Chernyakin (localspook)

Changes

C++17's CTAD obsoletes makeMatcher (and many make* functions like it).

The deduction guide is written out explicitly to avoid -Wctad-maybe-unsupported warnings.


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

4 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/utils/Matchers.h (+2-2)
  • (modified) clang/include/clang/ASTMatchers/ASTMatchersInternal.h (+1-6)
  • (modified) clang/include/clang/ASTMatchers/ASTMatchersMacros.h (+4-4)
  • (modified) clang/lib/Tooling/Transformer/RewriteRule.cpp (+2-2)
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<NamedDecl>
 matchesAnyListedName(llvm::ArrayRef<StringRef> 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<QualType>
 matchesAnyListedTypeName(llvm::ArrayRef<StringRef> 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<QualType>
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<T> without specifying
-/// the template type argument.
-template <typename T>
-inline Matcher<T> makeMatcher(MatcherInterface<T> *Implementation) {
-  return Matcher<T>(Implementation);
-}
+template <typename T> Matcher(MatcherInterface<T> *) -> Matcher<T>;
 
 /// 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<Type> 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<Type> 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<Type> (                     \
@@ -200,7 +200,7 @@
   }                                                                            \
   inline ::clang::ast_matchers::internal::Matcher<Type> 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<Type> 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 <typename T>
 ast_matchers::internal::Matcher<T>
 forEachDescendantDynamically(ast_matchers::BoundNodes Nodes,
                              DynTypedMatcher M) {
-  return ast_matchers::internal::makeMatcher(new BindingsMatcher<T>(
+  return ast_matchers::internal::Matcher(new BindingsMatcher<T>(
       std::move(Nodes),
-      ast_matchers::internal::makeMatcher(
+      ast_matchers::internal::Matcher(
           new DynamicForEachDescendantMatcher<T>(std::move(M)))));
 }
 

Copy link
Contributor

@nicovank nicovank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me, thanks! Let's wait for one more set of eyes. I did a quick search for this on GitHub, most hits seem to be in LLVM forks/clones, so it doesn't seem this will impact users (good to check even if internal code).

inline Matcher<T> makeMatcher(MatcherInterface<T> *Implementation) {
return Matcher<T>(Implementation);
}
template <typename T> Matcher(MatcherInterface<T> *) -> Matcher<T>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just a comment here indicating this is a user-defined deduction guide.

@vbvictor
Copy link
Contributor

vbvictor commented Jul 6, 2025

I'd suggest marking it [[deprecated]] for now and removing it completely after 2 releases of LLVM (AFAIK that's usual procedure).

I've searched for usages too, and it doesn't seem to be used anywhere, but I think we still need to take into account private forks. If it is used in clang/lib/Tooling/Transformer/RewriteRule.cpp, some custom checks/tooling could use it too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category clang-tidy clang-tools-extra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants