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?
Added to DStress as http://dstress.kuehne.cn/run/s/scope_17_A.d http://dstress.kuehne.cn/run/s/scope_17_B.d http://dstress.kuehne.cn/run/s/scope_17_C.d http://dstress.kuehne.cn/run/s/scope_17_D.d
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
*** This issue has been marked as a duplicate of issue 1894 ***