https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101645
Bug ID: 101645 Summary: -Wsign-conversion misses negation of unsigned int Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: matthew at wil dot cx Target Milestone: --- Test case: unsigned long a(void); void b(long); void c(void) { unsigned int x = a(); b(-x); } There is a missed warning in the call to b(). x is negated, but as an int. It is then passed to b() which sees a very large positive number instead of a small negative number. This has recently affected the Linux codebase, and it's disappointing that gcc doesn't have a warning that we could enable to find it. https://godbolt.org/z/xvaxh1rqr shows that Clang does spot this with -Wsign-conversion, but GCC currently doesn't (it only warns for line 4 and not line 5). Admittedly the Clang diagnostic message isn't the greatest, but at least it says _something_.