[clang-tools-extra] [clang-tidy] Fix false positive from `readability-redundant-typename` on partially specialized variables (PR #175473)

Yanzuo Liu via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 12 01:22:55 PST 2026


================
@@ -25,22 +25,25 @@ void RedundantTypenameCheck::registerMatchers(MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus20)
     return;
 
-  const auto InImplicitTypenameContext = anyOf(
-      hasParent(decl(anyOf(
-          typedefNameDecl(), templateTypeParmDecl(), nonTypeTemplateParmDecl(),
-          friendDecl(), fieldDecl(),
-          varDecl(hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl())),
-                  unless(parmVarDecl())),
----------------
zwuis wrote:

`hasTypeLoc`visits the type of variables only, so it works.

I tested `varDecl(forEach(typeLoc().bind("t")))` and `varDecl(forEachDescendant(typeLoc().bind("t")))`. The latter binds template arguments of variable template partial specializations, but the former only binds the type of variables, which is different from `hasParent` in this check. I'm investigating what's going on.

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


More information about the cfe-commits mailing list