[Bug c++/42810] Enumeration with sequential values has its for-loop exit condition optimized out.

tony3 at GarlandConsulting dot us gcc-bugzilla@gcc.gnu.org
Wed Jan 20 00:19:00 GMT 2010



------- Comment #8 from tony3 at GarlandConsulting dot us  2010-01-20 00:18 -------
I see what you mean.  I was looking at the "wrong side" of the "<=" and not
thinking about the reality that it would have to exceed the last valid value.
Pretty obvious once you point it out.

So now my question is why doesn't the compiler issue any warning about this?
The result is a silent "forever loop" and the program hangs.  Surely this is
not what the programmer intended?

I can appreciate that the compiler can make certain assumptions, but what I'm
really trying to say here is that to truly be helpful in programming a compiler
should either accept the code as valid (and try to do what is intended) or
issue a warning or error saying it won't or might not.

This is compounded by the fact that the code runs fine at lesser optimization
levels--and compiles silently at all levels.  So it is worse than silent, it is
misleading in that it allows this poor programming practice during development
only to turn it into a permanent hang in optimized production builds. :-)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42810



More information about the Gcc-bugs mailing list