[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 Jul 14 13:47:29 PDT 2025
================
@@ -66,22 +89,45 @@ void AvoidCArraysCheck::registerMatchers(MatchFinder *Finder) {
hasParent(varDecl(isExternC())),
hasParent(fieldDecl(
hasParent(recordDecl(isExternCContext())))),
- hasAncestor(functionDecl(isExternC())))),
+ hasAncestor(functionDecl(isExternC())),
+ isWithinImplicitTemplateInstantiation())),
std::move(IgnoreStringArrayIfNeededMatcher))
.bind("typeloc"),
this);
+
+ Finder->addMatcher(templateArgumentLoc(hasTypeLoc(hasType(arrayType())))
+ .bind("template_arg_with_array_type_loc"),
+ this);
}
void AvoidCArraysCheck::check(const MatchFinder::MatchResult &Result) {
- const auto *ArrayType = Result.Nodes.getNodeAs<TypeLoc>("typeloc");
+ TypeLoc ArrayTypeLoc{};
+
+ if (const auto *MatchedTypeLoc = Result.Nodes.getNodeAs<TypeLoc>("typeloc");
+ MatchedTypeLoc != nullptr) {
----------------
vbvictor wrote:
```suggestion
if (const auto *MatchedTypeLoc = Result.Nodes.getNodeAs<TypeLoc>("typeloc")) {
```
`operator=` already return `MatchedTypeLoc` and we check it for null
https://github.com/llvm/llvm-project/pull/132924
More information about the cfe-commits
mailing list