This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Spurious warning due to promotion rules
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Spurious warning due to promotion rules
- From: Zack Weinberg <zack at wolery dot cumb dot org>
- Date: Wed, 12 Jul 2000 17:33:22 -0700
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