www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14482] New: [SPEC] Goto's into catch blocks should be an error


          Issue ID: 14482
           Summary: [SPEC] Goto's into catch blocks should be an error
           Product: D
           Version: D1 & D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: ibuclaw gdcproject.org

It is illegal for a goto to enter a try or finally block in D.  For consistency
it should also be illegal to enter a catch block via goto also.

GDC has been emitting an error since 2010, but DMD will happily continue to
accept such code.


Previous ML discussions:
http://forum.dlang.org/post/j4m10o$cu6$1 digitalmars.com
http://forum.dlang.org/post/qwifroariomkblyxnbdw forum.dlang.org


Previous bug report which the fix was to disallow goto into TryStatement's.


This error is not documented as far as I can see (it should be!)


Previous bug report which introduced an error for goto's into catch blocks only
if an initialisation was skipped.



What the specification has to say about 'finally' blocks:

"A FinallyStatement may not exit with a goto, break, continue, or return; nor
may it be entered with a goto."
 -- http://dlang.org/statement.html#TryStatement

Reasoning for this (Quote from Walter in first ML link above):
"On a related note, doing a goto into a finally block is pretty problematic to
support because it's actually a mini-function."

In a way, GDC is exactly the same as DMD here, but also with try and catch
blocks.  The difference being that it's not a function, it is treated as an
isolated area/block that is inaccessible from the outside.


Apr 23 2015