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

            Bug ID: 86719
           Summary: case label does not reduce to an integer constant
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code sample is as follow:

int main(void)
{
 const int nFOO = 1;
 int nFoo = 0;

 switch(nFoo){
 case nFOO:
 exit(1);
 }
 exit(0);
}

gcc rejects the code:

gcc code1.c 
code1.c: In function 'main':
code1.c:7:2: error: case label does not reduce to an integer constant
  case nFOO:
  ^~~~
code1.c:8:2: warning: implicit declaration of function 'exit'
[-Wimplicit-function-declaration]
  exit(1);
  ^~~~
code1.c:8:2: warning: incompatible implicit declaration of built-in function
'exit'
code1.c:8:2: note: include '<stdlib.h>' or provide a declaration of 'exit'
code1.c:1:1:
+#include <stdlib.h>
 int main(void)
code1.c:8:2:
  exit(1);
  ^~~~
code1.c:10:2: warning: incompatible implicit declaration of built-in function
'exit'
  exit(0);
  ^~~~
code1.c:10:2: note: include '<stdlib.h>' or provide a declaration of 'exit'

The code looks legal. clang accepts it

Reply via email to