https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113852
Bug ID: 113852 Summary: -Wsign-compare doesn't warn on unsigned result types Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: admin at computerquip dot com Target Milestone: --- I haven't quite figured out the pattern here so the title may not be great. Some code may help explain better: https://godbolt.org/z/d8cqd1WqP ``` #include <iostream> #include <limits> #include <cinttypes> int main() { uint16_t a1 = std::numeric_limits<unsigned short>::max(); uint16_t a2 = std::numeric_limits<unsigned short>::max(); /* a1 * a2 should be 4294836225 in math terms */ uint64_t a3 = 4294836225; /* * The result of (a1 * a2) is of type int and the result is negative. * (a1 * a2) ends up as some bogus high number because the common * type here ends up as uint64_t and sign-extension occurs. */ if ((a1 * a2) > a3) { std::cout << "this will print\n"; } } ``` Some observations I've noticed: * If either a1 or a2 are constexpr, the warning will occur. * This used to warn up until 8.1. * Clang also doesn't warn here but MSVC will with /W3 or higher. * This seems like a slight variation of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101645