================
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits