This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Possible C++ bug: Are C enum tags unsigned?


> 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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]