[Issue 827] New: Trying to break out of a labelled BlockStatement breaks out of a for loop at its beginning

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 10 05:16:26 PST 2007


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

           Summary: Trying to break out of a labelled BlockStatement breaks
                    out of a for loop at its beginning
           Product: D
           Version: 1.00
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid, wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: smjg at iname.com


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

void main() {
    block: {
        for (int i = 0; i < 10; i++) {
            if (i == 5) break block;
        }
        writefln("Within block");
    }
    writefln("Outside block");
}
----------
Within block
Outside block
----------

I was expecting it to print only "Outside block".  However, according to the
spec, the code shouldn't compile:

http://www.digitalmars.com/d/statement.html
"If break is followed by Identifier, the Identifier  must be the label of an
enclosing while, for, do or switch statement, and that statement is exited. It
is an error if there is no such statement."

The restriction to while, for, do or switch seems arbitrary, but still....


-- 



More information about the Digitalmars-d-bugs mailing list