[clang] [clang] Add missing support for traversal kind in addMatcher overloads (PR #170953)

Victor Chernyakin via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 6 07:12:17 PST 2025


================
@@ -1681,7 +1681,13 @@ void MatchFinder::addMatcher(const DeclarationMatcher &NodeMatch,
 
 void MatchFinder::addMatcher(const TypeMatcher &NodeMatch,
                              MatchCallback *Action) {
-  Matchers.Type.emplace_back(NodeMatch, Action);
+  std::optional<TraversalKind> TK;
+  if (Action)
+    TK = Action->getCheckTraversalKind();
+  if (TK)
+    Matchers.Type.emplace_back(traverse(*TK, NodeMatch), Action);
+  else
+    Matchers.Type.emplace_back(NodeMatch, Action);
----------------
localspook wrote:

Up to you, but we could factor this logic out into a function like:
```cpp
template <typename T>
static internal::Matcher<T>
adjustTraversalKind(internal::Matcher<T> NodeMatch,
                    MatchFinder::MatchCallback *Action) {
  if (Action)
    if (std::optional<TraversalKind> TK = Action->getCheckTraversalKind())
      return traverse(*TK, NodeMatch);
  return NodeMatch;
}
```
then use it like:
```cpp
Matchers.TypeLoc.emplace_back(adjustTraversalKind(NodeMatch, Action), Action);
```

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


More information about the cfe-commits mailing list