This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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



------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]