Hi Brian et al., > My suspicion is that this is illegal to do with enums. as I found out having an enum out-of-range will result in undefined behavior. It worked for -O0, but in -O2 the compiler optimized away my "if (enumVar > lastEnumeration)" because this can never be true with valid enum values. As it didn't optimize it out in -O0 and as it works in GCC 4.5 I suspected a compiler-bug, which it seems not to be then of course. Cheers! Martin > On Thu, Aug 5, 2010 at 9:54 AM, <gcc@xxxxxxxx> wrote: > > Hello, > > > > I discovered what seems to be a bug in G++ 4.4 (that was not there in > > prior versions and seems already fixed in 4.5) and am wondering if > > there's some information available what exactly the problematic cases > > are, so that I know which places in my code to verify/adapt. > > > > It was a "caching" problem when -O2 was enabled and an enum variable was > > checked and increased in a loop and then finally checked again, all in > > some very near code-lines. The final check did get an old "cached" value > > of the variable, while the code below that worked with the actual value. > > > > When I changed the declaration of the variable from my enum type to > > "volatile" or to "int", then it worked. The question is if the following > > is probably illegal C++-code, although I don't think so? > > > > myEnumType myVariable; > > > > myVariable = myEnumType (myVariable + 2); > > > > (I extracted that piece of code into a small test-program and that > > worked, strangely.) > > > > If someone has answers to those two questions, that'd be very nice. > > Thanks so far for reading. > > > > Cheers! > > Martin