Consensus on goto's into catch blocks

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jun 13 12:18:14 PDT 2013


On Thu, Jun 13, 2013 at 11:50:49AM -0700, Brad Roberts wrote:
> On 6/13/13 10:35 AM, Iain Buclaw wrote:
> >Can someone remind me again what was last agreed when I brought this
> >up?
> >
> >I seem to recall that this should be disallowed as is practically
> >always a bug, also, and it skips any initialisation of the exception
> >object. (See: http://dlang.org/statement.html - "It is illegal for a
> >GotoStatement to be used to skip initializations.")
> >
> >Current failing test I want to have removed from the test suite.
> >
> >test/runnable/eh.d:
> >void test8()
> >{
> >   int a;
> >   goto L2;    // gdc Error: cannot goto into catch block
> >
> >   try {
> >       a += 2;
> >   }
> >   catch (Exception e) {
> >       a += 3;
> >L2: ;
> >       a += 100;
> >   }
> >   assert(a == 100);
> >}
> >
> >
> >Thanks
> >Iain.
> 
> I think it should be illegal, but not because it's a catch block but
> because of the initialization.  If the catch was just "catch
> (Exception)" then it shouldn't be illegal.

Why shouldn't it be illegal, though? I honestly don't see any use case
for such a strange construct. Not to mention, like monarch_dodra said,
if the anonymous Exception's reference is on the stack, then at the end
of the catch block there'd be code to adjust the stack pointer, which
will trash your stack pointer horribly if we goto the middle of the
block bypassing the stack allocation of the Exception reference.


T

-- 
What's a "hot crossed bun"? An angry rabbit.


More information about the Digitalmars-d mailing list