------- Comment #15 from mark at codesourcery dot com 2010-04-20 22:18 ------- Subject: Re: [DR 1022] G++ is too aggressive in optimizing away bounds checking with enums
jason at gcc dot gnu dot org wrote: > Certainly optimizing away bounds checking is good when it is provably > redundant, but that clearly doesn't apply to this case. Do you think this is different from signed integer overflow in loops? To me, it seems quite similar. That's a situation where the compiler will now optimize away the check in something like "for (int i = 0; i >= 0; ++i)", leaving us with an infinite loop. And, of course, that can hit you in a security context too. /* Here we know that "i" is positive. */ ... if (i + 100 <= 0) abort(); /* The check above will make sure this never overflows ... <scaryvoice>or will it?</scaryvoice> */ i += 100; > That said, I'll go ahead and add the option. Thanks, -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43680