https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113852
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Jonathan Wakely from comment #2) > I assume what's happening is that GCC assumes integer promotion from > uint16_t to int is value preserving and so we get two positive values, and > therefore comparison with an unsigned value is fine - there are no negative > values involved and so it doesn't matter that we're comparing int with > unsigned long. But of course that's not true here. We have two positive ints > but their product overflows to produce a negative int. I guess we're also > assuming no overflow happens, because that would be undefined and we assume > no UB. Ah yes, if you add -fwrapv then you get the -Wsign-compare warning, because now a negative product can occur without undefined overflow.