This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/42810] Enumeration with sequential values has its for-loop exit condition optimized out.
- From: "tony3 at GarlandConsulting dot us" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 20 Jan 2010 00:18:53 -0000
- Subject: [Bug c++/42810] Enumeration with sequential values has its for-loop exit condition optimized out.
- References: <bug-42810-18694@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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