I'm using gcc 4.9.0 and I would like to see compiler warn me about exceeded array bounds. If I compile this
int main()
{
int table[5]={0};
table[8] = 1234;
int x = table[10];
}
with g++ -O2 -Wall main.cpp -o main.exe I only get warning about unused x:
main.cpp: In function 'int main()':
main.cpp:8:7: warning: unused variable 'x' [-Wunused-variable]
int x = table[10];
^
From gcc documentation (https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options) I see that -O2 together with -Wall should enable -Warray-bounds=1 check. Things don't change if I try to add -Warray-bounds. As a matter of fact, the compiler doesn't even recognize -Warray-bounds=1:
g++: error: unrecognized command line option '-Warray-bounds=1'
Now, why doesn't compiler give any warning about incorrectly writing into / reading from the array? And why doesn't the compiler recognize '-Warray-bounds=1'?
=1or=0with-Woptions. Only-Wsome-warningor-Wno-some-warning.