This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

-fstrict-aliasing, -Wstrict-aliasing=2, and indirect conversions


Hello,

int main() {
    int a = 1;
    short *b = (short *) (char *) &a;
    *b = 2;
    return a;
}

This simple program returns 1 when compiled with -O2 -fstrict-aliasing, and 2 when compiled with -O2 -fno-strict-aliasing. It does not produce any warnings with -Wstrict-aliasing=2. According to the documentation:

`-Wstrict-aliasing=2'
     This option is only active when `-fstrict-aliasing' is active.  It
     warns about all code which might break the strict aliasing rules
     that the compiler is using for optimization.  This warning catches
     all cases, but it will also give a warning for some ambiguous
     cases that are safe.

Is this a bug? If so, what is the bug? Is the warning missing, or is the optimization invalid? And are there any alternative options that really catch every aliasing problem?

I'm using gcc 4.0.1 on i686-pc-linux-gnu.

Thanks in advance for any replies.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]