Consensus on goto's into catch blocks

Iain Buclaw ibuclaw at ubuntu.com
Thu Jun 13 18:09:48 PDT 2013


On 13 June 2013 23:53, Brad Roberts <braddr at puremagic.com> wrote:
> On 6/13/13 12:22 PM, Iain Buclaw wrote:
>>
>> On Thursday, 13 June 2013 at 18:51:01 UTC, 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.
>>
>>
>> This could be easily possible to do, and still keep 100% safe. But I must
>> still ask why why why,
>> Delilah, would you do that?
>
>
> Oh, just minimizing what's illegal.  _I_ wouldn't do that.

OK, and just out of curiosity, what's your view on jumps into try
statement blocks?

goto L2;

try {
  /* ... */
L2:
  /* ... */
}


Obviously the same rule must apply if the jump to the label skips over
any initialisations at the beginning of the try block above it...

--
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';


More information about the Digitalmars-d mailing list