https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104680
Bug ID: 104680 Summary: identical inner condition not detected Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: dcb314 at hotmail dot com Target Milestone: --- For this C++ code, with a identical inner condition: extern void g( int); void f( int n) { if (n > 31) { if (n > 31) { g( 2 * n); } } else g( n); } g++ currently has nothing to say: $ /home/dcb/gcc/results/bin/g++ -c -g -O2 -Wall -Wextra -Wduplicated-branches feb24e.cc $ cppcheck managed to find the problem, usually a result of sloppy cut'n'paste: feb24e.cc:8:9: warning: Identical inner 'if' condition is always true. [identicalInnerCondition] if (n > 31) ^ feb24e.cc:6:8: note: outer condition: n>31 if (n > 31) ^ feb24e.cc:8:9: note: identical inner condition: n>31 if (n > 31) ^ Here is a list of all the places in the gcc source code where this problem occurs: trunk.git/gcc/config/avr/avr.cc:8674:22: warning: Identical inner 'if' condition is always true. [identicalInnerCondition] trunk.git/gcc/config/mn10300/mn10300.cc:888:8: warning: Identical inner 'if' condition is always true. [identicalInnerCondition] trunk.git/gcc/d/expr.cc:689:17: warning: Identical inner 'if' condition is always true. [identicalInnerCondition] trunk.git/libffi/src/m32r/ffi.c:66:15: warning: Identical inner 'if' condition is always true. [identicalInnerCondition] trunk.git/liboffloadmic/runtime/offload_engine.cpp:113:13: warning: Identical inner 'if' condition is always true. [identicalInnerCondition] trunk.git/zlib/contrib/minizip/zip.c:1212:26: warning: Identical inner 'if' condition is always true. [identicalInnerCondition] There are also 67 cases of this in the current linux kernel, so it looks like it might be a real problem.