Bug 3549 – Bypassing initializers with goto -- Is this a bug?

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
Other
OS
Windows
Creation time
2009-11-24T13:42:00Z
Last change time
2014-04-18T09:12:06Z
Assigned to
nobody
Creator
anteusz

Comments

Comment #0 by anteusz — 2009-11-24T13:42:41Z
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 by clugdbug — 2009-11-24T20:00:14Z
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 by matti.niemenmaa+dbugzilla — 2009-11-25T01:38:02Z
*** This issue has been marked as a duplicate of issue 602 ***