[Issue 602] New: Compiler allows a goto statement to skip an initalization

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Nov 26 06:18:36 PST 2006


http://d.puremagic.com/issues/show_bug.cgi?id=602

           Summary: Compiler allows a goto statement to skip an
                    initalization
           Product: D
           Version: 0.175
          Platform: PC
               URL: http://www.digitalmars.com/d/statement.html#GotoStatemen
                    t
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: smjg at iname.com


The spec for GotoStatement states:

"It is illegal for a GotoStatement to be used to skip initializations."

However, this code compiles:

----------
import std.stdio;

void main() {
    goto qwert;

    int yuiop = 42;

qwert:
    writefln(yuiop);
}
----------
4294112
----------

The spec doesn't comment on the use of goto to skip a declaration with no
explicit initialization, but it has the same effect of bypassing the principle
that all variables in D are initialized (unless this behaviour is overridden
with a void).  In other words, this does the same:

----------
import std.stdio;

void main() {
    goto qwert;

    int yuiop;

qwert:
    writefln(yuiop);
}
----------

In both instances, a goto has been used to prevent a variable from being
initialized.  Essentially, the compiler treats the code as being equivalent to:

----------
import std.stdio;

void main() {
    int yuiop = void;

    writefln(yuiop);
}
----------


-- 




More information about the Digitalmars-d-bugs mailing list