This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Possible C++ bug: Are C enum tags unsigned?
- To: chip at valinux dot com
- Subject: Re: Possible C++ bug: Are C enum tags unsigned?
- From: Eli Zaretskii <eliz at delorie dot com>
- Date: Sat, 10 Jun 2000 01:41:31 -0400 (EDT)
- CC: gcc-bugs at gcc dot gnu dot org
- References: <20000609135531.V443@perlsupport.com>
- Reply-to: Eli Zaretskii <eliz at is dot elta dot co dot il>
> Date: Fri, 9 Jun 2000 13:55:31 -0700
> From: Chip Salzenberg <chip@valinux.com>
>
> I ask because gcc is reporting a signed/unsigned comparison on line
> 449 of gcc/cp/cfns.h:
>
> 449: else if (index < -TOTAL_KEYWORDS)
>
> Now, 'index' is of type 'int', and thus signed. So, by a process of
> elimination, I deduce that TOTAL_KEYWORDS is unsigned. (And, of
> course, arithmetic negation of an unsigned value is also unsigned.)
>
> Two questions: (1) Are enum tags _supposed_ to be unsigned?
> (2) If so, is this line buggy, or not?
The problem is in your code: you are abusing the enum type by
comparing it against an int, and by negating it. The only operations
which can meaningfully be used with an enum are assignment, equality,
and inequality. And you cannot mix enum with other data types, so the
above comparison has an undefined result.