scope(success) lowered to try-catch ?

Nicholas Wilson iamthewilsonator at hotmail.com
Sun Jun 17 12:10:33 UTC 2018


On Sunday, 17 June 2018 at 10:58:29 UTC, Cauterite wrote:
> Hello,
> I'm not sure whether I'm missing something obvious here, but is 
> there a reason for scope(success) being lowered to a try-catch 
> statement?
> I would have expected only scope(exit) and scope(failure) to 
> actually interact with exception handling, while scope(success) 
> simply places code on the path of normal control flow.
>
> Example (windows x32):
>
> ---
>
> // main.d
> void main() {
> 	scope(success) {}
> }
>
>> dmd -betterC main.d
> Error: Cannot use try-catch statements with -betterC
>
> ---
>
> Regardless of whether -betterC is used, you can see in the 
> disassembly that having a scope(success) anywhere in the 
> function causes the SEH prologue to be emitted in the code.
>
> Is there a reason scope(success) needs to set up for exception 
> handling?
> Or is this a bug / potential enhancement ?

I suspect scope(success) is lowered because scope(exit) and 
scope(failure)
are, and that would result in a simpler (compiler) implementation 
of it.

does adding nothrow to main fix it? For dcompute I specifically 
allow scope(exit|success) because there will never be any 
exceptions _at all_.

If not, please do submit an issue. Also a better error message 
should be given.


More information about the Digitalmars-d-learn mailing list