www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14887] New: break in static foreach should apply to outer scope

https://issues.dlang.org/show_bug.cgi?id=14887

          Issue ID: 14887
           Summary: break in static foreach should apply to outer scope
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: code dawg.eu

A break inside a static foreach loop is interpreted as "breaking" the foreach
loop. The static foreach doesn't have a scope and one cannot break it during
compile time. Instead the break will work at runtime.

----
import std.stdio;

void foo(Args...)()
{
    foreach (A; Args)
    {
        pragma(msg, A);
        writeln("runtime ", A.stringof);
        break;
    }
}

void main()
{
    foo!(int, long, float, double)();
}
----
int
long
float
double
runtime int
----

This is highly confusing, particularly when combined with switch (see issue
7835).
It would be best to deprecate the existing break and require a break with label
instead.

--
Aug 07 2015