Bug 16622 – multiple scope(exit) are damaging the stack
Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2016-10-18T14:19:00Z
Last change time
2016-10-22T16:34:38Z
Assigned to
nobody
Creator
robertw89
Comments
Comment #0 by robertw89 — 2016-10-18T14:19:22Z
Multiple scope(exit) blocks don't get rewind correctly.
This code produces a hard crash instead of a stacktrace caused by the assertion.
http://pastebin.com/NzZF1J2g
Comment #1 by safety0ff.bugz — 2016-10-18T15:16:02Z
doesn't matter what is thrown if the stack is corrupted :)
void main() {
scope(exit) {}
scope(exit) {throw new Exception("kab00m!"); }; return;
}
Comment #3 by mathias.lang — 2016-10-22T16:34:38Z
The specs explicitly mention you shouldn't do that:
> A scope(exit) or scope(success) statement may not exit with a throw, goto, break, continue, or return; nor may it be entered with a goto.
Ref: http://dlang.org/spec/statement.html#ScopeGuardStatement
It might work in some situations though (happen to work on Linux).
If you think it should always work feel free to bring it up on the N.G. or open an enhancement request with the rationale.