This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Parsing of switch statement


	Recently I have encountered some code that contains an empty case
statement at the end of a switch (see example below).  The code compiles under
gcc but not under g++.  I get the error
test.c: In function `int main (int, char **)':
test.c:9: parse error before `}' 
If I put a ';' after the case 0 : it will also compile under g++.  I've tried
this on sparc-sun-solaris2.5.1 with egcs-2.90.21 971202 (egcs-1.00 release)
and egcs-2.91.02 971206 (gcc-2.8.0); both give the same results.  Is this the
correct behavior?  Does the C++ spec require this?

	Craig

Here is the simple test

#include <stdio.h>

int main (int argc, char *argv[])
{
  int i=1;
  switch (i) {
  case 1 : printf ("1 ");
  case 0 : /* a ';' is needed here to compile with g++ */
  }
  printf ("\n");
  return 0;
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]