This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH RFC: Fix enum comparisons
- From: "Richard Guenther" <richard dot guenther at gmail dot com>
- To: "Joseph S. Myers" <joseph at codesourcery dot com>
- Cc: "Ian Lance Taylor" <iant at google dot com>, gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org
- Date: Thu, 4 Sep 2008 10:59:06 +0200
- Subject: Re: PATCH RFC: Fix enum comparisons
- References: <m3r680vp2x.fsf@google.com> <Pine.LNX.4.64.0809032326001.13593@digraph.polyomino.org.uk>
On Thu, Sep 4, 2008 at 1:26 AM, Joseph S. Myers <joseph@codesourcery.com> wrote:
> On Wed, 3 Sep 2008, Ian Lance Taylor wrote:
>
>> The first attachment below is the -Wenum-compare support. I don't
>> propose to apply that patch now, but I would be interested in any
>> comments from the C frontend maintainers. I have not yet updated the
>> documentation; basically, -Wenum-compare is the default in C++, and in
>> C it is enabled by -Wall or -Wc++-compat.
>
> The C patch seems fine (for stage 1) to me.
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)
Richard.