goto skipping declarations

claptrap clap at trap.com
Tue Sep 16 04:57:33 UTC 2025


void foo(bool x)
{
         goto END;
         uint what;
     END:
}

>> onlineapp.d(15): Error: `goto` skips declaration of variable 
>> `onlineapp.foo.what`
>>        goto END;
>>        ^

void foo(bool x)
{
     {
         goto END;
         uint what;
     }
     END:
}

runs fine.

I think it's correct behaviour, if the goto is jumping out of its 
scope, its OK to skip declarations in that scope, since they cant 
be accessed outside it.

But the documentation doesn't specify this behaviour. It just 
says...

"It is illegal for a GotoStatement to be used to skip 
initializations."

it should say something like "It is illegal for a GotoStatement 
to be used to skip initializations within its containing scope."


More information about the Digitalmars-d mailing list