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

            Bug ID: 111598
           Summary: Wimplicit-fallthrough print for a code that is not
                    compiled in
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Hi-Angel at yandex dot ru
  Target Milestone: ---

When a switch-case has a "fallthrough" case that is surrounded by an `#ifdef`
and is not compiled in, GCC does not recognize the `// fallthrough` comment and
prints a `this statement may fall through` warning.

# Steps to reproduce

    $ cat test2.c
    #include <stdio.h>

    int main() {
        enum {Field1, Field2} e = 0;
        switch (e) {
            case Field1:
                puts("field1");
                // fallthrough
    #ifdef SOME_UNDEFINED_MACRO
            case Field2:
                puts("field2");
                // fallthrough
    #endif
            default:
                puts("default");
        }
    }
    $ gcc test2.c -o /dev/null -Wimplicit-fallthrough
    test2.c: In function ‘main’:
    test2.c:7:13: warning: this statement may fall through
[-Wimplicit-fallthrough=]
        7 |             puts("field1");
          |             ^~~~~~~~~~~~~~
    test2.c:14:9: note: here
       14 |         default:
          |         ^~~~~~~


## Expected

No warning, because every case ends with a fallthrough comment

## Actual

There's a warning

Reply via email to