[PATCH] D53771: [clang-tidy] Avoid C arrays check

Jonas Toth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 4 04:23:32 PST 2018


JonasToth added inline comments.


================
Comment at: clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp:84
         "cppcoreguidelines-c-copy-assignment-signature");
+    CheckFactories.registerCheck<modernize::AvoidCArraysCheck>(
+        "cppcoreguidelines-avoid-c-arrays");
----------------
lebedev.ri wrote:
> JonasToth wrote:
> > please conserve the alphabetical order here
> Sorted all the `CheckFactories.registerCheck<>();` lines.
the `avoid-*` checks seem to be displaced now.


================
Comment at: clang-tidy/modernize/AvoidCArraysCheck.cpp:44
+              unless(anyOf(hasParent(varDecl(isExternC())),
+                           hasAncestor(functionDecl(isExternC())))))
+          .bind("typeloc"),
----------------
lebedev.ri wrote:
> JonasToth wrote:
> > What about struct-decls that are externC?
> Hm, what is a `struct-decl`?
we chatted in irc, but for reference
```
extern "C" {
struct Foo {

};
}
```


================
Comment at: test/clang-tidy/modernize-avoid-c-arrays.cpp:3
+
+int a[] = {1, 2};
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use std::array<> instead
----------------
what about variable-length arrays? I think they should be diagnosed as well, but plain replacement with `std::array` would be incorrect, more a `std::vector` would fit.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53771





More information about the cfe-commits mailing list