g++ 2.96 -W issues bogus warning for conditional expression with enum and unsigned

Nathan Sidwell nathan@codesourcery.com
Thu Jul 6 02:44:00 GMT 2000


Nathan Sidwell wrote:
> However, looking at Martin Sebor's example, the enumeration should be
> unsigned, so the warning should not be triggered -- I'll take a look.
Ok, digging deeper I find code in type_promotes_to (cvt.c), which
converts to int, if that can represent all the values of the enumeration.
However, I believe that is incorrect.

[4.5]/2 says an enumeration can be implicitly converted to the first of
`int', `unsigned int', `long' or `unsigned long' that can represent all
the values of the underlying type. I.e. not simply all the values of the
enumeration.

[7.2]/5 says the underlying type is an integral type that can represent
all the enumerator values. It is implementation define as to which integral
type is chosen.

We choose `unsigned int' for enumerations with non-negative values,
so those should promote to `unsigned int', not `int'. [4.5]/2 would
promote an `unsigned short' underlying type to `int' in preference to
`unsigned int', if we had such things.

Is there a language lawyer in the house?

nathan

-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org


More information about the Gcc-bugs mailing list