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

             Bug #: 55772
           Summary: "Jump crosses initialization" error spurious when var
                    is unused
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: matth...@urlichs.de


This is not an error if the variable in question is not accessed below the jump
target. The optimizer should detect this condition and not issue the warning.

Also, -fpermissive is ineffective because the third line is not affected.

This code works when I rename foo.cpp to foo.c.

$ >cat foo.cpp <<_END
int bar(int);

void foo(int check)
{
        if(check) goto end;
        int x = 123;
        x=bar(x);
        x=bar(x);
        end:
        bar(999);
}
_END
$ gcc -Wall -O3 -o foo.o -c foo.cpp
foo.cpp: In function ‘void foo(int)’:
foo.cpp:9:2: error: jump to label ‘end’ [-fpermissive]
foo.cpp:5:17: error:   from here [-fpermissive]
foo.cpp:6:6: error:   crosses initialization of ‘int x’
$ gcc -Wall -O3 -o foo.o -c foo.cpp -fpermissive
foo.cpp: In function ‘void foo(int)’:
foo.cpp:9:2: warning: jump to label ‘end’ [-fpermissive]
foo.cpp:5:17: warning:   from here [-fpermissive]
foo.cpp:6:6: error:   crosses initialization of ‘int x’
$ echo $?
1
$

Reply via email to