(gcc) conversion warning on ternary operator
I'm curious as to why the ternary operator gives me a sign conversion warning (-Wsign-compare), when an if statement does not:
number is a long long
Code:
unsigned long long n = number < 0 ? ULLONG_MAX + number + 1 : number;
As opposed to:
Code:
unsigned long long n;
if (number < 0)
n = ULLONG_MAX + number + 1;
else
n = number;
The implicit conversion is safe, which gcc seems to understand from the if statement, but not from the ternary operator, which would require me to explicitly cast the last operand in order for the error to go away.
Is this just the compiler being a bit dumb, or is there something else to the ternary operator that makes it harder for the compiler?