From 68f67eacb113a9c97f22d9134237f2a3baf6f09b Mon Sep 17 00:00:00 2001 From: siddhesh Date: Tue, 20 Feb 2018 11:11:31 +0000 Subject: 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@257843 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/cp-objcp-common.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gcc/cp/cp-objcp-common.c') diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c index a45dda4d012..5289a89e486 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) -- cgit v1.2.1