[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
Fri Sep 5 11:55:11 PDT 2025
================
@@ -39,6 +39,53 @@ AST_MATCHER(clang::ParmVarDecl, isArgvOfMain) {
return FD ? FD->isMain() : false;
}
+template <typename TargetType, typename NodeType>
+const TargetType *getAs(const NodeType *Node) {
+ if constexpr (std::is_same_v<NodeType, clang::DynTypedNode>)
+ return Node->template get<TargetType>();
+ else
+ return llvm::dyn_cast<TargetType>(Node);
+}
+
+AST_MATCHER(clang::TypeLoc, isWithinImplicitTemplateInstantiation) {
+ const auto IsImplicitTemplateInstantiation = [](const auto *Node) {
+ const auto IsImplicitInstantiation = [](const auto *Node) {
+ return (Node != nullptr) && (Node->getTemplateSpecializationKind() ==
+ TSK_ImplicitInstantiation);
+ };
+ return (IsImplicitInstantiation(getAs<clang::CXXRecordDecl>(Node)) ||
+ IsImplicitInstantiation(getAs<clang::FunctionDecl>(Node)) ||
+ IsImplicitInstantiation(getAs<clang::VarDecl>(Node)));
+ };
+
+ DynTypedNodeList ParentNodes = Finder->getASTContext().getParents(Node);
+ const clang::NamedDecl *ParentDecl = nullptr;
+ while (!ParentNodes.empty()) {
+ const DynTypedNode &ParentNode = ParentNodes[0];
+ if (IsImplicitTemplateInstantiation(&ParentNode))
+ 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>()))
----------------
vbvictor wrote:
```suggestion
if (ParentDecl = ParentNode.template get<clang::NamedDecl>())
```
Do we need double `(` here?
https://github.com/llvm/llvm-project/pull/132924
More information about the cfe-commits
mailing list