[Bug c++/52954] Missing bounds check warning

xinliangli at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu Apr 12 21:56:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52954

--- Comment #1 from davidxl <xinliangli at gmail dot com> 2012-04-12 21:56:07 UTC ---
Another example:

constexpr int arr_size = 42;
 constexpr int N = 44;
 void f(int);
 int test() {
   int arr[arr_size];
  // ...
   f(arr[N]);
   // ...
  if (N < arr_size) return arr[N];
  return 0;
 }

/*

deadcode.cpp:7:5: warning: array index 44 is past the end of the array
(which contains 42 elements) [-Warray-bounds]
 f(arr[N]);
   ^   ~
deadcode.cpp:5:3: note: array 'arr' declared here
 int arr[arr_size];
 ^
1 warning generated.

*/



More information about the Gcc-bugs mailing list