markus@x4 /tmp % cat fall.c void bar(int); void foo(int i) { switch (i) { case 1: { bar(1); // fall-through } case 2: bar(2); default: break; } } markus@x4 /tmp % gcc -Wimplicit-fallthrough=1 -c fall.c fall.c: In function ‘foo’: fall.c:6:5: warning: this statement may fall through [-Wimplicit-fallthrough=] bar(1); ^~~~~~ fall.c:9:3: note: here case 2: ^~~~ As you can see gcc issues a bogus warning and doesn't warn for the case 2 fallthrough.
(In reply to Markus Trippelsdorf from comment #0) > As you can see gcc issues a bogus warning and doesn't warn for the case 2 > fallthrough. It falls through to default: break; so it should warn for that case.
(In reply to Marek Polacek from comment #1) > (In reply to Markus Trippelsdorf from comment #0) > > As you can see gcc issues a bogus warning and doesn't warn for the case 2 > > fallthrough. > > It falls through to default: break; so it should warn for that case. Yes, that is what I meant to say.
Another issue: markus@x4 /tmp % cat fall.c void bar(int); template <typename T> void foo(int i, bool bo) { switch (i) { case 1: if (!bo) break; // Fall through. case 2: bar(2); default: break; } } template void foo<int>(int, bool); template void foo<void*>(int, bool); markus@x4 /tmp % g++ -Wimplicit-fallthrough=1 -c fall.c fall.c: In function ‘void foo(int, bool) [with T = int]’: fall.c:6:5: warning: this statement may fall through [-Wimplicit-fallthrough=] if (!bo) ^~ fall.c:9:3: note: here case 2: ^~~~ fall.c: In function ‘void foo(int, bool) [with T = void*]’: fall.c:6:5: warning: this statement may fall through [-Wimplicit-fallthrough=] if (!bo) ^~ fall.c:9:3: note: here case 2: ^~~~
It'll be hard to "fix" the first testcase: <https://gcc.gnu.org/ml/gcc-patches/2016-10/msg00841.html>.
(In reply to Marek Polacek from comment #4) > It'll be hard to "fix" the first testcase: > <https://gcc.gnu.org/ml/gcc-patches/2016-10/msg00841.html>. Thanks. The testcase from comment 3 is a dup of pr77886 and fixed by the patch that Jakub posted there. So if there is already an existing bug for the first testcase, feel free to close this bug.
Ah, right. Ok. *** This bug has been marked as a duplicate of bug 77817 ***