[Bug c++/32080] New: Can goto a function try-block

andrew dot stubbs at st dot com gcc-bugzilla@gcc.gnu.org
Fri May 25 09:15:00 GMT 2007


It should not be possible to jump into a function try-block.

The example from the standard, clause 15/2, is rejected properly:

void f() {
  goto l1;      // Ill-formed
  goto l2;      // Ill-formed
  try {
    goto l1;    // OK
    goto l2;    // Ill-formed
    l1: ;
  } catch (...) {
    l2: ;
    goto l1;    // Ill-formed
    goto l2;    // OK
  }
}

t.cxx: In function ‘void f()’:
t.cxx:7: error: jump to label ‘l1’
t.cxx:2: error:   from here
t.cxx:7: error:   enters try block
t.cxx:9: error: jump to label ‘l2’
t.cxx:6: error:   from here
t.cxx:9: error:   enters catch block
t.cxx:9: error: jump to label ‘l2’
t.cxx:3: error:   from here
t.cxx:9: error:   enters catch block
t.cxx:7: error: jump to label ‘l1’
t.cxx:10: error:   from here
t.cxx:10: error:   enters try block

But, if the example is adjusted to use a *function* try-block, then it's a
different story:

void f()
try {
  goto l1;      // OK
  goto l2;      // Ill-formed
  l1: ;
} catch (...) {
  l2: ;
  goto l1;      // Ill-formed
  goto l2;      // OK
}

t.cxx: In function ‘void f()’:
t.cxx:7: error: jump to label ‘l2’
t.cxx:4: error:   from here
t.cxx:7: error:   enters catch block

The jump into the catch block has been caught, but the jump into the try-block
has been missed.

I know that the standard does not explicitly say that you can't jump into a
_function_ try-block, but it does say you can't jump into a try-block, and this
is merely a variant. Certainly the motivation would be the same in both cases.


-- 
           Summary: Can goto a function try-block
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: andrew dot stubbs at st dot com


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



More information about the Gcc-bugs mailing list