http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58540
Bug ID: 58540 Summary: Incorrect warning message for '*=' statement and different results based on optimization Product: gcc Version: 4.7.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: bernardwidynski at gmail dot com Created attachment 30900 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30900&action=edit Example program which generates incorrect message The code shown below generates a warning message c_ex.c: In function ‘main’: c_ex.c:15:8: warning: operation on ‘u.y’ may be undefined [-Wsequence-point] c_ex.c:15:8: warning: ‘u.y’ is used uninitialized in this function [-Wuninitialized] Also, when compiled with optimization -O3, it prints the correct result. When compiled without optimization it prints a zero. Obviously, u.y is initialized. It is set to x + r. The compiler should not generate a warning message and should produce the same results regardless of the optimization level. ------------------------------------------------------------------------- #include <stdio.h> static double r = 0.; static double x = 2.7182818284590452353602; int main (void) { union { double y; unsigned int w[2]; } u; /* Set y = (x + r) squared */ u.y *= u.y = x + r; printf("y = %lf\n",u.y); return 0; }