hi all, I wrote a simple testcase with some type prunned pointer and compiled it with -O2 option. I assumed that gcc would issue some warnings as told in its documents. But i am afraid that no warnings at all. I have to specify the -Wstrict-aliasing or -Wall option manually. Is this a document inconsistency or a little bug, or what else I should pay attention to before doing the test? I have tried differenct version of gcc in Ubuntu 8.04/8.10, none warnings for gcc-3.3/3.4/4.2/4.3 .
In GCC's documents(http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html) "-Wstrict-aliasing This option is only active when -fstrict-aliasing is active. It warns about code which might break the strict aliasing rules that the compiler is using for optimization. The warning does not catch all cases, but does attempt to catch the more common pitfalls. It is included in -Wall. It is equivalent to -Wstrict-aliasing=3 " and -O2 would active -fstrict-aliasing by default, which should also active this options. BTW: the simple testcase: 1 #include <stdio.h> 2 3 int main() 4 { 5 int a = 0x12345678; 6 short *p = (short *)&a; 7 short temp; 8 temp = *p; 9 *p = *(p+1); 10 *(p+1) = temp; 11 printf("%x\n", a); 12 } Thanks. Best, Jim