------- Comment #9 from tony3 at GarlandConsulting dot us  2010-01-20 15:42 
-------
I am reopening this bug if only because I'd like to get a response to my
previous comments.  

I can appreciated that, in your view, the compiler is 'technically correct' in
making the assumption that it need not support programs which inadvertently
generate an enumeration value outside of the defined range.

But if you step back from this 'technical legitimacy', and look at the bigger
picture, we are left with a compiler which is not doing much to help us write
reliable code.  In fact, it is doing just the opposite by silently accepting
such code and even running it in the expected fashion when optimization is less
than -O2.

It is one thing to state that the compiler doesn't have to support a value
which is greater than 1 less than the closest power of two, and another to make
a compiler which usefully indicates when it refuses to follow where the
programmer is directing it to go.

All the more so when its refusal to implement an exit loop--indeed completely
expunging the expected exit condition from the code--hinges on such a rare
combination of incident:  1) optimization set at -O2, and 2) a maximum
enumeration value which happens to fall just under a power of two.  Unless this
unhappy combination occurs, the code misleadingly does as the programmer
expects.  (Also, I would venture to say that many programmers would be
extremely surprised to find that powers of 2 which fit well within 8-bits are
apparently to be included in this behavior: 8, 16, 32, 64, 128.)

So, given that those who know much more about enumerations and compilers than I
ever will have decided that such behavior is not to be improved upon, why is it
that we get no warning about it?  Isn't the intention of warnings to indicate
to the programmer when they have done something silly or dangerous where the
results may differ from their expectations?  Surely this situation falls into
that category.

The fact that there have been two bug reports in this regard and that a number
of experienced programmers at my site found the resulting execution completely
puzzling and unexpected would seem to indicate some sort of response beyond
"this is technically acceptable therefore the bug report is INVALID . . .
next!" is in order?


-- 

tony3 at GarlandConsulting dot us changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42810

Reply via email to