This PR reports a bogus -Wimplicit-fallthrough warning on the attached test. The problem is that last_stmt_in_scope should for GIMPLE_TRY, if the last statement of the eval part can't fallthrough, return this statement and don't warn. And the same should be true for FALLTHROUGH (). This patch fixes it.
Bootstrapped/regtested on x86_64-linux, ok for trunk? 2016-09-30 Marek Polacek <pola...@redhat.com> PR c++/77803 * gimplify.c (last_stmt_in_scope): Add check for FALLTHROUGH (). * g++.dg/warn/Wimplicit-fallthrough-1.C: New test. diff --git gcc/gimplify.c gcc/gimplify.c index 66bb8be..97d63db 100644 --- gcc/gimplify.c +++ gcc/gimplify.c @@ -1687,6 +1687,7 @@ last_stmt_in_scope (gimple *stmt) stmt = gimple_seq_last_stmt (gimple_try_eval (try_stmt)); gimple *last_eval = last_stmt_in_scope (stmt); if (gimple_stmt_may_fallthru (last_eval) + && !gimple_call_internal_p (last_eval, IFN_FALLTHROUGH) && gimple_try_kind (try_stmt) == GIMPLE_TRY_FINALLY) { stmt = gimple_seq_last_stmt (gimple_try_cleanup (try_stmt)); diff --git gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C index e69de29..8f80b01 100644 --- gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C +++ gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C @@ -0,0 +1,16 @@ +// PR c++/77803 +// { dg-do compile { target c++11 } } +// { dg-options "-Wimplicit-fallthrough" } + +struct A {}; +int a; +void fn1() { + switch (0) { + case 0: { + A b; + [[fallthrough]]; + } + default: + a = 0; + } +} Marek