This is GCC Bugzilla
This is GCC Bugzilla Version 2.20+
View Bug Activity | Format For Printing | Clone This Bug
The following program doesn't run properly when compiled with -O #include <stdio.h> enum OptionStateEnum { SLEEPING, ACTIVE, INTENDED, DESIRED, EXECUTED, ABORTED }; int main() { OptionStateEnum l[2] = { EXECUTED, ACTIVE }; OptionStateEnum state; for ( int i = 0; i < 2; ++i ) { state = l[i]; printf( "state = %d\n", state ); if ( ( state == DESIRED ) || ( state == INTENDED ) || ( state == ACTIVE ) ) { printf( "break state = %d\n", state ); break; } } return 0; } The program was compiled using the following command: gcc -O -g0 optimize-enum.cpp -o optimize-enum.exe Resulting in the following output: state = 4 break state = 4 When compiled with -O0 the output is as expected: state = 4 state = 1 break state = 1 The problem also vanishes when checking for 4 or only 2 enums in the if-statement. Or when assigning explicit values to the enums (0, 2, 4, 8, 16, 32, 64). Cheers, Michael Gollin
This is a dup of bug 15069 which is fixed for 3.4.1. *** This bug has been marked as a duplicate of 15069 ***
Reopen as I marked it as a wrong bug as a dup of.
*** This bug has been marked as a duplicate of 16372 ***