================
@@ -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) {
+    ArrayTypeLoc = *MatchedTypeLoc;
+  }
+
+  if (const auto *TemplateArgLoc = Result.Nodes.getNodeAs<TemplateArgumentLoc>(
+          "template_arg_with_array_type_loc");
+      TemplateArgLoc != nullptr &&
+      TemplateArgLoc->getTypeSourceInfo() != nullptr) {
+    ArrayTypeLoc = TemplateArgLoc->getTypeSourceInfo()->getTypeLoc();
+  }
+
+  // check whether an actual array type got matched (see checks above)
+  if (ArrayTypeLoc.isNull()) {
+    return;
+  }
----------------
vbvictor wrote:

I think we don't expect `ArrayTypeLoc` to be null, so write `assert`.
https://llvm.org/docs/CodingStandards.html#assert-liberally

https://github.com/llvm/llvm-project/pull/132924
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to