[Bug c/92479] missing warnings for unreachable codes with break (i.e. revive the subset of -Wunreachable-code that fits under clang's -Wunreachable-code-break)
egallager at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sat Jan 22 21:27:28 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92479
--- Comment #14 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to David Binderman from comment #12)
> Interestingly, both gcc and clang have nothing to say about this code:
>
> extern void g( int);
>
> void f( int a)
> {
> if (a >= 0)
> {
> if (a < 0)
> {
> g(a);
> }
> }
> }
>
> $ /home/dcb/gcc/results/bin/gcc -c -g -O2 -Wall -Wextra -Wunreachable-code
> jan20e.cc
> $
>
> cppcheck finds the problem:
>
> $ cppcheck --enable=all jan20e.cc
> Checking jan20e.cc ...
> jan20e.cc:10:9: warning: Opposite inner 'if' condition leads to a dead code
> block. [oppositeInnerCondition]
> if (a < 0)
> ^
> jan20e.cc:8:8: note: outer condition: a>=0
> if (a >= 0)
> ^
That's bug 82100, which is already linked under "See Also"
More information about the Gcc-bugs
mailing list