[clang-tools-extra] [clang-tidy] do not diagnose array types within implicit instantiations of a template (PR #132924)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 26 05:15:11 PDT 2025
================
@@ -39,6 +39,51 @@ AST_MATCHER(clang::ParmVarDecl, isArgvOfMain) {
return FD ? FD->isMain() : false;
}
+AST_MATCHER(clang::TypeLoc, isWithinImplicitTemplateInstantiation) {
+ const auto IsImplicitTemplateInstantiation = [](const auto *Node) {
+ return (Node != nullptr) &&
+ (Node->getTemplateSpecializationKind() == TSK_ImplicitInstantiation);
+ };
+
+ DynTypedNodeList ParentNodes = Finder->getASTContext().getParents(Node);
+ const clang::NamedDecl *ParentDecl = nullptr;
+ while (!ParentNodes.empty()) {
+ const DynTypedNode &ParentNode = ParentNodes[0];
+ if (IsImplicitTemplateInstantiation(
+ ParentNode.template get<clang::CXXRecordDecl>()) ||
+ IsImplicitTemplateInstantiation(
+ ParentNode.template get<clang::FunctionDecl>()) ||
+ IsImplicitTemplateInstantiation(
+ ParentNode.template get<clang::VarDecl>()))
+ return true;
+
+ // in case of a `NamedDecl` as parent node, it is more efficient to proceed
+ // with the upward traversal via DeclContexts (see below) instead of via
+ // parent nodes
+ if (ParentDecl = ParentNode.template get<clang::NamedDecl>())
+ break;
+
+ ParentNodes = Finder->getASTContext().getParents(ParentNode);
+ }
+
+ if (ParentDecl != nullptr) {
+ const clang::DeclContext *DeclContext = ParentDecl->getDeclContext();
+ while (DeclContext != nullptr) {
+ for (const clang::Decl *Decl : DeclContext->decls()) {
+ if (IsImplicitTemplateInstantiation(
+ dyn_cast<clang::CXXRecordDecl>(Decl)) ||
+ IsImplicitTemplateInstantiation(
+ dyn_cast<clang::FunctionDecl>(Decl)) ||
+ IsImplicitTemplateInstantiation(dyn_cast<clang::VarDecl>(Decl)))
----------------
vbvictor wrote:
Could these calls to 3 functions be refactored in a separate function to avoid duplicates with L52-57
https://github.com/llvm/llvm-project/pull/132924
More information about the cfe-commits
mailing list