D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1087 - scope(exit) is ignored if preceded by a label
Summary: scope(exit) is ignored if preceded by a label
Status: RESOLVED DUPLICATE of issue 1894
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P2 critical
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2007-03-30 17:04 UTC by Jarrett Billingsley
Modified: 2014-02-16 15:21 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jarrett Billingsley 2007-03-30 17:04:08 UTC
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?
Comment 2 Gide Nwawudu 2009-03-19 15:27:46 UTC
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 Walter Bright 2010-05-28 21:38:56 UTC

*** This issue has been marked as a duplicate of issue 1894 ***