https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120121
Bug ID: 120121 Summary: Comparison of integer expressions of different signedness not detected Product: gcc Version: 15.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: stefano.d at posteo dot de Target Milestone: --- Created attachment 61326 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61326&action=edit Not detected comparison of different signedness There is a not detected integer promotion when two variables are multiplied and the result is not stored into a variable. This compiles with -Wall -O1 -Wextra -Wshadow -Weffc++ -Wno-long-long -pedantic -pedantic-errors -std=c++14 ``` #include <cstdint> bool square_less_than_method_A(uint16_t a, uint64_t b) { // a * a does integer promotion return (a * a < b); } int main(int, char**) { return 0; } ``` See also: https://godbolt.org/z/jz8Ka8asn When the result is assigned into a variable, GCC detects the comparison of integer expressions of different signedness: ``` #include <cstdint> bool square_less_than_method_B(uint16_t a, uint64_t b) { const auto a_squared = a * a; return a_squared < b; } int main(int, char**) { return 0; } ``` The error is correctly reported: ``` <source>: In function 'bool square_less_than_method_B(uint16_t, uint64_t)': <source>:5:22: warning: comparison of integer expressions of different signedness: 'const int' and 'uint64_t' {aka 'long unsigned int'} [-Wsign-compare] 5 | return a_squared < b; | ~~~~~~~~~~^~~ ``` See also: https://godbolt.org/z/dfY749vdd