Bug 77955 - -Wimplicit-fallthrough=1 issue
Summary: -Wimplicit-fallthrough=1 issue
Status: RESOLVED DUPLICATE of bug 77817
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-12 13:41 UTC by Markus Trippelsdorf
Modified: 2016-10-12 16:17 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Trippelsdorf 2016-10-12 13:41:57 UTC
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.
Comment 1 Marek Polacek 2016-10-12 13:49:41 UTC
(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.
Comment 2 Markus Trippelsdorf 2016-10-12 13:56:24 UTC
(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.
Comment 3 Markus Trippelsdorf 2016-10-12 14:15:31 UTC
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:
   ^~~~
Comment 4 Marek Polacek 2016-10-12 15:07:49 UTC
It'll be hard to "fix" the first testcase: <https://gcc.gnu.org/ml/gcc-patches/2016-10/msg00841.html>.
Comment 5 Markus Trippelsdorf 2016-10-12 15:54:11 UTC
(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.
Comment 6 Marek Polacek 2016-10-12 16:17:40 UTC
Ah, right.  Ok.

*** This bug has been marked as a duplicate of bug 77817 ***