http://d.puremagic.com/issues/show_bug.cgi?id=7835
Summary: Ignored break inside static foreach Product: D Version: D2 Platform: x86 OS/Version: Windows Status: NEW Keywords: wrong-code Severity: normal Priority: P2 Component: DMD AssignedTo: nob...@puremagic.com ReportedBy: bearophile_h...@eml.cc --- Comment #0 from bearophile_h...@eml.cc 2012-04-05 17:40:12 PDT --- This D2 program compiles with no warnings or errors with DMD 2.059beta: import core.stdc.stdio: printf; template TypeTuple(TList...) { alias TList TypeTuple; } void main() { char c = 'b'; switch (c) { case 'a': printf("1 a\n"); break; foreach (o; TypeTuple!('b', 'c')) { case o: printf("2 %c\n", c); break; } default: printf("default"); } } But it runs in a wrong way, as you see: ...>dmd -run test.d 2 b default ...>dmd -w -run test.d test.d(12): Error: switch case fallthrough - use 'goto default;' if intended So the break inside the static foreach is ignored. (This idiom of using a static foreach inside a switch is handy to generate switch cases.) Note: adding a second break, like this, doesn't improve the situation: import core.stdc.stdio: printf; template TypeTuple(TList...) { alias TList TypeTuple; } void main() { char c = 'b'; switch (c) { case 'a': printf("1 a\n"); break; foreach (o; TypeTuple!('b', 'c')) { case o: printf("2 %c\n", c); break; break; } default: printf("default"); } } test.d(10): Warning: statement is not reachable test.d(10): Warning: statement is not reachable test.d(12): Error: switch case fallthrough - use 'goto default;' if intended -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------