http://d.puremagic.com/issues/show_bug.cgi?id=7835
Dmitry Olshansky <dmitry.o...@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dmitry.o...@gmail.com --- Comment #1 from Dmitry Olshansky <dmitry.o...@gmail.com> 2012-04-06 07:15:55 PDT --- (In reply to comment #0) > 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'; L_MySwitch: > switch (c) { > case 'a': printf("1 a\n"); break; > foreach (o; TypeTuple!('b', 'c')) { > case o: printf("2 %c\n", c); break L_MySwitch; > } > default: printf("default"); > } > } > > For these cases I recommend to use labeled breaks so that it's more clear for humans and compiler alike. > > 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"); > } > } It can't help because the second break is by definition unreachable. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------