problem with enumerations
Chandrasekhar Murthy
murthy@sgi.com
Thu Jul 20 10:37:00 GMT 2000
I have enclosed email exchange with Alexandre Olivia regarding the
problem.
On Jul 17, 2000, Chandrasekhar Murthy <murthy@sgi.com> wrote:
> I am using Cygnus drop 20000530, and noticed that the following
> program narrowed down from the Spec 2000 bencmarks, now
> gets into an infinite loop.
>
> typedef enum {RANK1, RANK2, RANK3, RANK4, RANK5, RANK6, RANK7, RANK8}
> ranks;
> main ()
> {
> int rank;
> for (rank=RANK8;rank>=RANK1;rank--) {
> }
> }
Indeed.
> The gcc ChangeLog shows the following
>
> 2000-05-24 Alexandre Oliva <aoliva@cygnus.com>
> * c-decl.c (build_enumerator): Don't modify the value's type,
> convert it.
I don't think this change is related with the introduction of the
bug. It appears to me that the bug would have already occurred
before.
The problem is that the C Standard states explicitly that
enumeration-constants have type `int', but GCC may use `unsigned' in
case all enumeration tags are unsigned, or even a wider integer type
if needed. It is the conversion of the enumeration-constants to
an unsigned type that causes the problem, because then `rank' is
promoted to unsigned, so it is always >= 0 = RANK1.
> I was wondering whether you encounter the same problem with the
> stock gcc compiler
Yup. Please file a bug report. GCC is in error.
I seem to recall a recent thread discussing this issue in the public
GCC mailing list. I wasn't paying much attention by that time,
though.
More information about the Gcc-bugs
mailing list