[Issue 14887] New: break in static foreach should apply to outer scope
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Aug 7 14:16:46 PDT 2015
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 at puremagic.com
Reporter: code at 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.
--
More information about the Digitalmars-d-bugs
mailing list