[Bug c/92487] New: case label error when label is made from character of C string

SztfG at yandex dot ru gcc-bugzilla@gcc.gnu.org
Tue Nov 12 21:52:00 GMT 2019


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

            Bug ID: 92487
           Summary: case label error when label is made from character of
                    C string
           Product: gcc
           Version: 9.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: SztfG at yandex dot ru
  Target Milestone: ---

testcase:

void test(char x)
{
  switch (x)
  { 
    case "abc"[0]: // error: case label does not reduce to an integer constant
      printf("a\n");
      break;
    case "abc"[1]: // error: case label does not reduce to an integer constant
      printf("b\n");
      break;
    default:
      printf("other\n"); 
      break;   
  }
}

clang and icc is able to compile this.

Clang with -pedantic telling
> warning: expression is not an integer constant expression; folding it to a constant is a GNU extension [-Wgnu-folding-constant]
https://godbolt.org/z/xvGJB4

So this is some GNU extension, but why GCC doesn't support it?


More information about the Gcc-bugs mailing list