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

            Bug ID: 106929
           Summary: declaration in switch-case doesn't fail since GCC 11
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sigmaepsilon92 at gmail dot com
  Target Milestone: ---

this code should fail because declarations inside switch-cases aren't allowed
without {}:
void fn(int a) {
    switch (a) {
        case 0:
            int c = 5;
            break;
    }
}

Starting with gcc 11 this doesn't fail to compile anymore though.
The expected error message would look like this:

<source>: In function 'fn':
<source>:4:13: error: a label can only be part of a statement and a declaration
is not a statement
    4 |             int c = 5;
      |             ^~~
Compiler returned: 1

Reply via email to