[clang-tools-extra] [clang-tidy] Switch misc-confusable-identifiers check to a faster algorithm. (PR #130369)

Julian Schmidt via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 19 14:45:21 PDT 2025


================
@@ -181,42 +160,105 @@ void ConfusableIdentifierCheck::check(
   if (!ND)
     return;
 
-  IdentifierInfo *NDII = ND->getIdentifier();
+  addDeclToCheck(ND, cast<Decl>(ND->getDeclContext()
+                                    ->getNonTransparentContext()));
+
+  // Associate template parameters with this declaration of this template.
+  if (const auto *TD = dyn_cast<TemplateDecl>(ND)) {
+    for (const NamedDecl *Param : *TD->getTemplateParameters())
+      addDeclToCheck(Param, TD->getTemplatedDecl());
+  }
+
+  // Associate function parameters with this declaration of this function.
+  if (const auto *FD = dyn_cast<FunctionDecl>(ND)) {
+    for (const NamedDecl *Param : FD->parameters())
+      addDeclToCheck(Param, ND);
+  }
+}
+
+void ConfusableIdentifierCheck::addDeclToCheck(const NamedDecl *ND,
----------------
5chmidti wrote:

Thinking about clangd and incomplete code, I think this is the only part in your changes I would suggest adding additional `nullptr` handling (for `ND` and `Parent`), just to be on the safe side.

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


More information about the cfe-commits mailing list