c++: Fix spurious fallthrough warning on break
authorSiddhesh Poyarekar <siddhesh@sourceware.org>
Tue, 20 Feb 2018 11:11:31 +0000 (11:11 +0000)
committerSiddhesh Poyarekar <siddhesh@gcc.gnu.org>
Tue, 20 Feb 2018 11:11:31 +0000 (11:11 +0000)
commitd3eb902f7f45cc20b5802b2ef3c85b88fdec52c0
treed2a38f0b7b33dc609127d7b35d5e8333ffcf2b21
parent5bbccd92506c4d260eca29d12fa30c75aaaee65b
c++: Fix spurious fallthrough warning on break

The C++ frontend generates a break that results in the fallthrough
warning misfiring in nested switch blocks where cases in the inner
switch block return, rendering the break pointless.  The fallthrough
detection in finish_break_stmt does not work either because the
condition is encoded as an IF_STMT and not a COND_EXPR.

Fix this by adding a condition for IF_STMT in the
langhooks.block_may_fallthru for C++.  Fix tested on x86_64.

gcc/cp
        * cp-objcp-common.c (cxx_block_may_fallthru): Add case for
        IF_STMT.

gcc/testsuite
        * g++.dg/nested-switch.C: New test case.

From-SVN: r257843
gcc/cp/ChangeLog
gcc/cp/cp-objcp-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-3.C [new file with mode: 0644]