------- Comment #3 from bangerth at math dot tamu dot edu 2010-04-08 03:18 ------- Subject: Re: G++ is too aggressive in optimizing away bounds checking with enums
> Except that the conversion is defined to produce an unspecified > value, not undefined behavior. A strict reading of that suggests to me > that the compiler is supposed to truncate on conversion so the resulting > value is one of the values of the enumeration, but that's certainly not > what we want. I'm really not in a position to argue standardese with you, but my reading based on the paragraph I cited is that the enumeration has a certain range of values it can represent (which may be larger than the set of values in the enumeration). In my interpretation, any assignment of values outside the range must necessarily produce (unspecified) values within this range. I can see no reason to prohibit a compiler from applying a mask every time. W. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43680