[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 5 14:13:53 PST 2015


alexfh added inline comments.

================
Comment at: clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp:56
@@ +55,3 @@
+    ArraySize = SizeArg.getAsIntegral();
+  }
+
----------------
We can go for a local setting for now, and if we introduce global or module-wide options, we can clean up these local settings in a single step.

================
Comment at: test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp:50
@@ +49,3 @@
+  a[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: array index 10 is past the end of the array (which contains 10 elements)
+  a[const_index(7)] = 3;
----------------
What's the difference between this warning and the -Warray-bounds compiler diagnostic that is turned on by default?
```
$ cat /tmp/q.cc 
void f() {
  int a[7];
  a[10];
}
$ clang_check /tmp/q.cc --
...
/tmp/q.cc:3:3: warning: array index 10 is past the end of the array (which contains 7 elements) [-Warray-bounds]
  a[10];
  ^ ~~
/tmp/q.cc:2:3: note: array 'a' declared here
  int a[7];
  ^
```


http://reviews.llvm.org/D13746





More information about the cfe-commits mailing list