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

            Bug ID: 103639
           Summary: [REGRESSION] GCC 11.2 (or even earlier) breaks switch
                    case with break in fast enumeration loop
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: objc
          Assignee: unassigned at gcc dot gnu.org
          Reporter: js-gcc at webkeks dot org
  Target Milestone: ---

The following code is miscompiled by GCC 11.2.1. I don't know when this
started, but this is a regression and used to work just fine in older version:

for (id object in someCollection) {
  switch (someVar) {
  case 0:
     puts("0");
     break;
  }
  puts("this should print but doesn't");
}

The break breaks out of the for loop instead of the switch case.

Changing the code to this makes it work:

for (id object in someCollection) {
  if (someVar == 0) {
     puts("0");
     break;
  }
  puts("this should print and does");
}

This worked just fine with older GCC versions and also works fine with all
versions of Clang.

Reply via email to