www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 602] New: Compiler allows a goto statement to skip an initalization

reply d-bugmail puremagic.com writes:
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 digitalmars.com
        ReportedBy: smjg 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);
}
----------


-- 
Nov 26 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=602





------- Comment #1 from deewiant gmail.com  2007-03-30 13:06 -------
Switch statements can also contain initializations prior to any case or
default. This is either a symptom of this bug, or an enhancement request. I'll
leave it here for now:

void main() {
        switch (1) {
                int x;
                case 1: assert (x == x.init);
        }
}


-- 
Mar 30 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=602


Matti Niemenmaa <matti.niemenmaa+dbugzilla iki.fi> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anteusz freemail.hu


--- Comment #2 from Matti Niemenmaa <matti.niemenmaa+dbugzilla iki.fi>
2009-11-25 01:38:02 PST ---
*** Issue 3549 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 25 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=602


Lars T. Kyllingstad <bugzilla kyllingen.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #3 from Lars T. Kyllingstad <bugzilla kyllingen.net> 2010-08-17
09:51:02 PDT ---
*** Issue 4667 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 17 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=602


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
            Version|0.175                       |D1 & D2
         AssignedTo|nobody puremagic.com        |bugzilla digitalmars.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 26 2010