https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38470
--- Comment #29 from Matthias Kretz (Vir) <mkretz at gcc dot gnu.org> --- (In reply to Vincent Lefèvre from comment #28) > (In reply to Matthias Kretz (Vir) from comment #27) > > Fair enough. But how can the compiler be certain that the developer realized > > u and u % 100 is unsigned? Maybe when (s)he wrote the code the expectation > > was for the RHS to be within [-99..99]. > > Indeed. (I never use % when its LHS can be either positive or negative, so > that I didn't think about this case.) FWIW, personally I could use a warning whenever I use % on variables that can potentially be negative. Because my mental model of % N is that I get a result in [0..N-1]. I tried to fix it but my head is stubborn. ;) > Now, the cause of the bug in such a case would be that the user messed up > with the signedness of u, not because he forgot about the promotion rule. > This is something rather different. Right. But if that's the case wouldn't a warning about the unexpected promotion be useful? (which -Wsign-compare happens to provide) To reduce the noise, I won't argue this point any further and let whoever actually implements a fix for the PR decide. :)