PATCH RFC: Fix enum comparisons

Ian Lance Taylor iant@google.com
Thu Sep 4 17:21:00 GMT 2008


"Joseph S. Myers" <joseph@codesourcery.com> writes:

> On Thu, 4 Sep 2008, Richard Guenther wrote:
>
>> Note that I think -Wenum-compare should _not_ be enabled with -Wall.
>> That is, I suppose -Wenum-compare will warn about comparing against
>> integer constants as well, which is commonly used in C code that
>> defines bitmask members as enums like
>> 
>> enum C { bit1 = 1, bit2 = 2, bit3 = 4 };
>> 
>> and then do
>> 
>> enum C x;
>> if (x == bit1 | bit2)
>
> My understanding is that the patch only warns for comparisons involving 
> two different enums, not those involving an enum and a non-enum integer.

That is correct.  That is also the behaviour of g++.

Ian



More information about the Fortran mailing list