[Bug c/37231] New: GCC does not compile code with label statements that are followed by a declaration

colding at 42tools dot com gcc-bugzilla@gcc.gnu.org
Mon Aug 25 09:51:00 GMT 2008


Hi,

The following simple code does not build using GCC 3.3 or 4.x:

###### main.c ########
int
main(int argc, char *argv[])
{
        goto out;
out:
        int retv = 0;
        return retv;
}
#######################

GCC tells me:

####### GCC output ########
main.c: In function ‘main’:
main.c:7: error: syntax error before ‘int’
main.c:8: error: ‘retv’ undeclared (first use in this function)
main.c:8: error: (Each undeclared identifier is reported only once
main.c:8: error: for each function it appears in.)
###########################

I'm not aware that the above code should be invalid so I think this is a
compiler bug. Putting a ';' after the label will make the code compile just
fine:

###### working main.c ########
int
main(int argc, char *argv[])
{
        goto out;
out: ;
        int retv = 0;
        return retv;
}
##############################

Best regards,
  jules


-- 
           Summary: GCC does not compile code with label statements that are
                    followed by a declaration
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: colding at 42tools dot com
  GCC host triplet: i686-apple-darwin9


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



More information about the Gcc-bugs mailing list