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]

Spurious warning due to promotion rules


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

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