[PATCH] D13746: [clang-tidy] add check cppcoreguidelines-pro-bounds-constant-array-index

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 12 06:07:31 PST 2015


alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Looks good with one comment.

Thank you!


================
Comment at: clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp:107
@@ +106,3 @@
+    diag(Matched->getExprLoc(),
+         "array index %0 is before the beginning of the array")
+        << Index.toString(10);
----------------
To avoid confusion, I suggest explicitly stating that this is an std::array, not a regular array ("std::array<> index %0 is before ..."). Same for the message below.

Also, it's fine to have this in clang-tidy for now, but ultimately, it may be reasonable and more consistent to analyze this in Clang as a part of -Warray-bounds. However, I'm not sure whether it's better to make a library-specific warning in Clang or introduce some annotation to tell the compiler that it can statically check indexes using a certain expression, for example.


http://reviews.llvm.org/D13746





More information about the cfe-commits mailing list