Pelles C forum

Pelles C => Bug reports => Topic started by: FRex on March 05, 2019, 11:02:37 pm

Title: Comparing unsigned int with unsigned char produces different signedness warning
Post by: FRex on March 05, 2019, 11:02:37 pm
Example program:
Code: (C) [Select]
int main(void)
{
    unsigned int x = 0u;
    unsigned char y = 0u;
    return x > y;
}

Code: [Select]
main.c(5): warning #2251: Operands of '>' have types with different signedness: 'unsigned int' and 'int'.
I report it because I consider this incorrect since both operands are clearly unsigned. MSVC, clang and gcc do not generate such erroneous warning in this situation either (but would if y was just 'int').

I'm guessing this appears because unsigned char is first promoted to int (which is signed) and then the compiler just sees (signed) int being compared with unsigned int, forgetting that this int came from an integer promotion of a smaller unsigned integer type.
Title: Re: Comparing unsigned int with unsigned char produces different signedness warning
Post by: Pelle on March 10, 2019, 10:06:53 pm
Uncommon case, but I will look at it some day...
Title: Re: Comparing unsigned int with unsigned char produces different signedness warning
Post by: FRex on March 10, 2019, 10:19:35 pm
I ran into it in one file (lparser.c) of Lua 5.1