dmd v2.065 compatibility

Chris wendlec at tcd.ie
Fri Mar 14 03:56:22 PDT 2014


On Friday, 14 March 2014 at 10:49:57 UTC, bearophile wrote:
> Chris:
>
>> [2]
>> Another issue I encountered was when I recompiled the library, 
>> dmd 2.065 gave me an error that a goto statement skipped a 
>> variable. The case is as follows:
>>
>> if (condition) {
>>  goto Label;
>> }
>>
>> auto variable = getVariableValue(); // Only needed, if 
>> "condition" above not true
>> // do things with variable here (needed for what comes after 
>> "Label"
>>
>> Label:
>> // Finish everything
>>
>> I know that scope would be better and this is the only goto I 
>> have left. In order for the code to compile I had to move (as 
>> a quick fix)
>>
>> auto variable = getVariableValue();
>>
>> to before the if (condition) statement. Is this by design?
>
> D specs state that gotos can't be used to skip a variable 
> definition. In the last compiler version this rule has being 
> implemented and enforced. So the original code was not 
> D-conformant.
>
> Bye,
> bearophile

Thanks for the answer. Any particular reason why the variable 
declaration should not be skipped? Security? Code generation?


More information about the Digitalmars-d-learn mailing list