The following code:

int main( int argc, char** argv )
{
        switch ( 1 )
        {
                case 1:
                        int bug = 0;
                        break;
        }
        return 0;
}

is valid C syntax and should compile, but gcc gives the error:
bug.c: In function 'main':
bug.c:6: error: expected expression before 'int'

gcc doesn't properly interpret the variable declaration immediately following
the "case 1:" However, if another statement is inserted (even a blank
statement, just a semicolon) such as:

int main( int argc, char** argv )
{
        switch ( 1 )
        {
                case 1:
                        ; // workaround
                        int bug = 0;
                        break;
        }
        return 0;
}

gcc compiles this fine.

I have successfully reproduced this on multiple platforms both 32 bit and 64
bit in gcc 4.1.1 and 4.0.2. I suspect earlier and intermediate versions suffer
from this bug as well.


-- 
           Summary: parser bug for variable declaration immediately
                    following case statement in switch block
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: trivial
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: alx at gotnull dot net
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29444

Reply via email to