On 6/17/18 6:58 AM, 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 think you are right, adding scope(success) should just add the
statements to the end of the scope.
Here's what I think happens: Because scope(anything) needs to put things
like this:
try
{
normal code
scope(success) code
} catch(Exception e) {
scope(failure) code
throw e;
} finally {
scope(exit) code
}
so any time you use a scope statement, it has to set up this framework
so it can have the correct place to put things (there may be
scope(failure) or scope(exit) code later). But I think we can fix this.
-Steve