[clang-tools-extra] [clang-tidy] Avoid expensive AST traversal in RedundantTypenameCheck (PR #170540)

Paul Kirth via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 5 16:05:56 PST 2025


================
@@ -18,9 +18,13 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::readability {
 
 void RedundantTypenameCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(typeLoc(unless(hasAncestor(decl(isInstantiated()))))
-                         .bind("nonDependentTypeLoc"),
-                     this);
+  Finder->addMatcher(
+      typeLoc(loc(TypeMatcher(anyOf(typedefType(), tagType(),
+                                    deducedTemplateSpecializationType(),
+                                    templateSpecializationType()))),
+              unless(hasAncestor(decl(isInstantiated()))))
+          .bind("nonDependentTypeLoc"),
+      this);
----------------
ilovepi wrote:

Well, with the updated addMatcher overloads, the simple check you have above seems to work correctly. I put up #170953 to address the overloads, and then I think this PR can just do the simplified check once that lands.

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


More information about the cfe-commits mailing list