D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3549 - Bypassing initializers with goto -- Is this a bug?
Summary: Bypassing initializers with goto -- Is this a bug?
Status: RESOLVED DUPLICATE of issue 602
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-24 13:42 UTC by anteusz
Modified: 2014-04-18 09:12 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 anteusz 2009-11-24 13:42:41 UTC
Compile and execute this program:
import std.stdio;
void main()
{
	goto here;
	int a=1;
	{
		int b=2;
		{
			int c=3;
			{
				int d=4;
				here:
				writefln("%d %d %d %d",a,b,c,d);
			}	
			
			
		}	
		
	}	
	
}

Should it be 1,2,3,4?

I got
0 4226665 13 4526524
Comment 1 Don 2009-11-24 20:00:14 UTC
I don't know. That's an interesting case for safe D. In safe D, either the initializers must be executed, or bypassing them must be banned. The code below is an example of memory corruption. But as @safe isn't yet implemented (so far it only checks for use of asm, AFAIK), it's not a bug yet.

-----
class Foo { int x; }

@safe
void foo()
{
   goto xxx;
   Foo a = new Foo();
xxx:
   a.x = 8;
}
Comment 2 Matti Niemenmaa 2009-11-25 01:38:02 UTC

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