[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
Mon Apr 28 23:22:51 PDT 2025
================
@@ -39,6 +39,30 @@ AST_MATCHER(clang::ParmVarDecl, isArgvOfMain) {
return FD ? FD->isMain() : false;
}
+bool isWithinImplicitTemplateInstantiation(const TypeLoc *MatchedTypeLoc,
----------------
vbvictor wrote:
Also, if this function is still needed, we should move it to matchers.
The easy way is to write
```cpp
AST_MATCHER(clang::TypeLoc, isWithinImplicitTemplateInstantiation) {
...
}
```
And add it to
```cpp
unless(anyOf(
hasParent(parmVarDecl(isArgvOfMain())),
hasParent(varDecl(isExternC())),
hasParent(fieldDecl(hasParent(recordDecl(isExternCContext())))),
hasAncestor(functionDecl(isExternC())),
isWithinImplicitTemplateInstantiation())),
```
But I think that this function should not be even needed because we can write something like:
```cpp
AST_POLYMORPHIC_MATCHER(isImplicitTemplateSpecialization,
AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, VarDecl,
CXXRecordDecl)) {
return (Node.getTemplateSpecializationKind() == TSK_ImplicitInstantiation);
}
auto IsInImplicitTemplateInstantiation =
anyOf(hasAncestor(cxxRecordDecl(isImplicitTemplateSpecialization())),
hasAncestor(functionDecl(isImplicitTemplateSpecialization())),
hasAncestor(varDecl(isImplicitTemplateSpecialization())));
Finder->addMatcher(
typeLoc(hasValidBeginLoc(), hasType(arrayType()),
unless(IsInImplicitTemplateInstantiation),
//...
```
I guess example will have the same semantics as your function.
https://github.com/llvm/llvm-project/pull/132924
More information about the cfe-commits
mailing list