Bug 1087 – scope(exit) is ignored if preceded by a label
Status
RESOLVED
Resolution
DUPLICATE
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2007-03-30T17:04:00Z
Last change time
2014-02-16T15:21:38Z
Keywords
wrong-code
Assigned to
nobody
Creator
jarrett.billingsley
Comments
Comment #0 by jarrett.billingsley — 2007-03-30T17:04:08Z
Have a look:
scope class A
{
~this()
{
writefln("A dtor");
}
}
void main()
{
int x = 5;
switch(x)
{
case 5:
scope a = new A();
scope(exit) writefln("exit");
writefln("five");
break;
}
switch(x)
{
case 5:
goto _something;
_something:
scope a = new A();
scope(exit) writefln("exit");
writefln("something");
break;
}
}
This outputs:
five
exit
A dtor
something
exit
You'll notice the first switch works correctly -- "five", then "exit", then "A dtor" are printed, as expected. But the second switch jumps to a label (common when you have several cases which have a common ending code) inside the switch. In this case, the scope(exit) statement prints "exit", but the scope class's dtor is never called.
Related to 1041?
import std.stdio;
void main() {
start: // Comment this line.
scope(exit)
writefln("exit");
writefln("Got Here");
}
'exit' is not output if start: label is present.
C:\> test
Got Here
Comment #3 by bugzilla — 2010-05-28T21:38:56Z
*** This issue has been marked as a duplicate of issue 1894 ***