diff options
author | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2018-02-20 11:11:31 +0000 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@gcc.gnu.org> | 2018-02-20 11:11:31 +0000 |
commit | d3eb902f7f45cc20b5802b2ef3c85b88fdec52c0 (patch) | |
tree | d2a38f0b7b33dc609127d7b35d5e8333ffcf2b21 /gcc/cp/cp-objcp-common.c | |
parent | 5bbccd92506c4d260eca29d12fa30c75aaaee65b (diff) | |
download | gcc-d3eb902f7f45cc20b5802b2ef3c85b88fdec52c0.zip gcc-d3eb902f7f45cc20b5802b2ef3c85b88fdec52c0.tar.gz gcc-d3eb902f7f45cc20b5802b2ef3c85b88fdec52c0.tar.bz2 |
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
Diffstat (limited to 'gcc/cp/cp-objcp-common.c')
-rw-r--r-- | gcc/cp/cp-objcp-common.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c index a45dda4..5289a89 100644 --- a/gcc/cp/cp-objcp-common.c +++ b/gcc/cp/cp-objcp-common.c @@ -349,6 +349,11 @@ cxx_block_may_fallthru (const_tree stmt) case THROW_EXPR: return false; + case IF_STMT: + if (block_may_fallthru (THEN_CLAUSE (stmt))) + return true; + return block_may_fallthru (ELSE_CLAUSE (stmt)); + case SWITCH_STMT: return (!SWITCH_STMT_ALL_CASES_P (stmt) || !SWITCH_STMT_NO_BREAK_P (stmt) |