scope() statements and return
Shammah Chancellor via Digitalmars-d
digitalmars-d at puremagic.com
Fri Oct 3 22:08:38 PDT 2014
On 2014-10-03 19:35:31 +0000, Andrei Alexandrescu said:
>> Better yet:
>>
>> int func() {
>> scope(exit)
>> return 1;
>> scope(exit)
>> return 2;
>> return 0;
>> }
>
> 2
That should return 1 as the return 1 is the last thing to execute.
SDC currently doesn't disallow this and correctly produces 1.
It'll be lowered as such:
int foo2()
{
try {
try {
return 0;
} finally {
return 2;
}
} finally {
return 1;
}
}
>
>> Worse yet:
>>
>> // What does this function do? What *should* it do??
>> int func() {
>> scope(success)
>> throw new Exception("");
>> scope(failure)
>> return 1;
>> return 0;
>> }
>
> 1
This throws an exception, as it's already outside of the scope(failure)
block and into the finally for success;
-S
More information about the Digitalmars-d
mailing list