[Issue 1087] New: Scope classes not destroyed in labeled statements in switches
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Mar 30 15:04:09 PDT 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1087
Summary: Scope classes not destroyed in labeled statements in
switches
Product: D
Version: 1.010
Platform: PC
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: jarrett.billingsley at gmail.com
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?
--
More information about the Digitalmars-d-bugs
mailing list