https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90457

            Bug ID: 90457
           Summary: -Wimplicit-fallthrough seems confused by #ifdef
           Product: gcc
           Version: 8.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc-bugs at engestrom dot ch
  Target Milestone: ---

Consider the following code:

```
int main(int argc, char *argv[])
{
  switch (argc)
  {
#ifdef HAVE_FOO
    case 1:
      if (argv[1])
        return 1;
      /* fallthrough */
#endif
    default:
        return 0;
  }
}
```

```
$ gcc -Wimplicit-fallthrough foo.c -o foo
```
As expected.

```
$ gcc -Wimplicit-fallthrough foo.c -o foo -DHAVE_FOO
foo.c: In function ‘main’:
foo.c:7:10: warning: this statement may fall through [-Wimplicit-fallthrough=]
       if (argv[1])
          ^
foo.c:11:5: note: here
     default:
     ^~~~~~~
```
This warning should have been suppressed by the comment purposefully left
there.

The same code with the `#ifdef` & `#endif` lines removed behaves as expected
(warning without the comment, no warning with the comment).

It looks like GCC is getting confused by the presence of the #ifdef lines.

Reply via email to