Spurious warning due to promotion rules

Zack Weinberg zack@wolery.cumb.org
Wed Jul 12 17:33:00 GMT 2000


Consider:

int foo (unsigned int A, unsigned short B, int x, int y)
{
   return x ? A : (y ? B : 0);
}

When compiled with -W -Wall, this provokes the "signed and unsigned
type in conditional expression" warning.  If B and A are swapped, the
warning goes away.  This is because the constant 0 is given type int,
which is wider than unsigned short, so (y ? B : 0) winds up being type
int.  Correct behavior per C99, but irritating in this context.

I don't have a good suggestion for what to do about it.  The best idea
I have is to force the inner expression to be unsigned iff we are not
going to complain about the types at that level being signed and
unsigned.  But that may break the promotion rules in a noticeable way,
and may just change the set of spurious warnings.

zw


More information about the Gcc-bugs mailing list