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: "jakub at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 Jan 2010 23:56:21 -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 #7 from jakub at gcc dot gnu dot org 2010-01-19 23:56 -------
This testcase also uses out of range enum value, so has undefined behavior as
well. For ENUM_VALUE_LAST which is a power of 2 minus 1 the for loop condition
still lets the body to be executed, then id = static_cast<ENUM_VALUE>(id+1)
i.e. id = static_cast<ENUM_VALUE>(ENUM_VALUE_LAST+1) is the out of range value.
The compiler can assume that no enum value is larger than ENUM_VALUE_LAST if it
is a power of 2 minus 1 (i.e. the largest value of the underlying type).
--
jakub at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42810