https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82100
Bug ID: 82100 Summary: gcc cannot detect unreachable code even when -Wunreachable-code is in effect Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: dcb314 at hotmail dot com Target Milestone: --- Given the following C code extern void g( int); void f( int a, int b) { if (a != b) { if (a == b) { g( a); } } if (a < b) { if (a >= b) { g( a); } } if (a > b) { if (a <= b) { g( a); } } } then recent gcc trunk doesn't have much to say, even when provoked: $ ~/gcc/results/bin/gcc -c -O2 -Wall -Wextra -Wunreachable-code -Wtautological-compare sep4a.cc $ Here is static analyser cppcheck finding the three bugs: $ ~/cppcheck/trunk/cppcheck --enable=all sep4a.cc [sep4a.cc:6] -> [sep4a.cc:8]: (warning) Opposite inner 'if' condition leads to a dead code block. [sep4a.cc:13] -> [sep4a.cc:15]: (warning) Opposite inner 'if' condition leads to a dead code block. [sep4a.cc:20] -> [sep4a.cc:22]: (warning) Opposite inner 'if' condition leads to a dead code block. $ Runng cppcheck over the current Linux kernel version 4.13 suggests about half a dozen bugs would be detected.