https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38470

--- Comment #26 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
(In reply to Matthias Kretz (Vir) from comment #25)
> (In reply to Piotr Engelking from comment #24)
> > It would be nice if the compiler noticed that rhs is always within
> > 0..SHRT_MAX, so the comparison is not surprisingly affected by integer
    ^^^^^^^^^^^
> > promotion.
> 
> The problem is the LHS which can be negative and has to be promoted to
> `unsigned int`. This promotion changes the value from s to UINT_MAX + 1 + s.
> I don't think this example is a case where -Wsign-compare should be silent.

But if I understand Piotr Engelking's point, UINT_MAX + 1 + s is not in the
range 0..SHRT_MAX mentioned above, thus cannot be equal to u % 100. Said
otherwise, the promotion has no visible effect here (if s is negative, then the
comparison will be false, as if promotion did not occur), so that there is no
need to warn.

That said, this is very specific code, and it might not be worth to handle it.
And IMHO, this is more than what this PR is about.

Reply via email to