https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111525
Bug ID: 111525 Summary: Inconsistent Wsign-compare in c++ with ubsan Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: zhroma at gcc dot gnu.org Target Milestone: --- $ cat test.cc extern long global; int foo (unsigned x) { return x == ((global ? 64 : 32) - 1) / 8; } $ gcc -x c -c -Werror=sign-compare test.cc $ gcc -x c -c -Werror=sign-compare test.cc -fsanitize=undefined $ gcc -x c++ -c -Werror=sign-compare test.cc $ gcc -x c++ -c -Werror=sign-compare test.cc -fsanitize=undefined test.cc: In function ‘int foo(unsigned int)’: test.cc:4:12: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Werror=sign-compare] 4 | return x == ((global ? 64 : 32) - 1) / 8; | ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1plus: some warnings being treated as errors Warning appears only for C++ with ubsan enabled. It seems that both sanitizer and warning are implemented in front-end part, and C++ somehow issues warning after instrumentation. This actually breaks ubsan-bootstrap with -Werror enabled, from what I know all versions since gcc-8 are affected. configure --enable-languages=c,c++ --disable-multilib --with-build-config=bootstrap-ubsan --enable-werror=yes && make BOOT_CFLAGS="-Wno-error=array-bounds -Wno-error=format-overflow" -Wno-error=array-bounds and -Wno-error=format-overflow are necessary as these warnings have known issues under ubsan.