[Issue 7835] switch case fallthrough error despite a break inside static foreach
https://issues.dlang.org/show_bug.cgi?id=7835 Mathias Lang changed: What|Removed |Added Status|REOPENED|RESOLVED CC||mathias.l...@sociomantic.co ||m Resolution|--- |INVALID --- Comment #12 from Mathias Lang --- I think the bug report from c4 and c11 is actually a diagnostic issue: https://issues.dlang.org/show_bug.cgi?id=7390 The original motivation for this bug report was actually not a bug. It has been proposed as an ER by Martin here: https://issues.dlang.org/show_bug.cgi?id=14887 So, since both the ER and the bug found are reported, I'll close this again. Feel free to direct any further discussion to the bug report or the ER, or reopen if I missed something. --
[Issue 7835] switch case fallthrough error despite a break inside static foreach
https://issues.dlang.org/show_bug.cgi?id=7835 Alex Parrill changed: What|Removed |Added CC||initrd...@gmail.com --- Comment #11 from Alex Parrill --- This also happens if you use return instead of break in the foreach loop, which should be valid (since return doesn't care about loops): import std.stdio; import std.typetuple; alias SwitchCases = TypeTuple!("a", "b", "c"); int main() { string s = "a"; switch(s) { case "special": writeln("Special case!"); return 0; foreach(c; SwitchCases) { case c: writeln(c); return 1; } default: writeln("default case"); return 2; } } $ rdmd -w ~/test.d /home/col/test.d(21): Warning: switch case fallthrough - use 'goto default;' if intended The switch works properly even if you ignore the warning, and moving the special case to after the foreach loop removes the warning. --
[Issue 7835] switch case fallthrough error despite a break inside static foreach
http://d.puremagic.com/issues/show_bug.cgi?id=7835 --- Comment #10 from timon.g...@gmx.ch 2012-04-06 15:21:47 PDT --- (In reply to comment #9) > I think that the expansion of the static foreach is wrong. It explains the > behavior, but doesn't excuse it. > > I think the bug report is valid. What would be your expected behavior? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 7835] switch case fallthrough error despite a break inside static foreach
http://d.puremagic.com/issues/show_bug.cgi?id=7835 Brad Roberts changed: What|Removed |Added Status|RESOLVED|REOPENED CC||bra...@puremagic.com Resolution|INVALID | --- Comment #9 from Brad Roberts 2012-04-06 15:11:51 PDT --- I think that the expansion of the static foreach is wrong. It explains the behavior, but doesn't excuse it. I think the bug report is valid. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 7835] switch case fallthrough error despite a break inside static foreach
http://d.puremagic.com/issues/show_bug.cgi?id=7835 bearophile_h...@eml.cc changed: What|Removed |Added Status|REOPENED|RESOLVED Resolution||INVALID --- Comment #8 from bearophile_h...@eml.cc 2012-04-06 13:12:01 PDT --- (In reply to comment #7) > Your code is expanded to: > > void main() { > char c = 'b'; > switch (c) { > case 'a': printf("1 a\n"); break; > {case 'b': printf("2 %c\n", c); goto break_foreach;} > {case 'c': printf("2 %c\n", c); goto break_foreach;} > break_foreach: break; > default: printf("default"); > } > } Thank you again Timon :-) So there is no bug here. This was not easy to understand for me. (Maybe D newbies will enjoy to read an example of this in some D tips&trickls somewhere, or maybe it was just a conceptualization problem of mine.) Issue closed again, as invalid. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 7835] switch case fallthrough error despite a break inside static foreach
http://d.puremagic.com/issues/show_bug.cgi?id=7835 --- Comment #7 from timon.g...@gmx.ch 2012-04-06 11:41:49 PDT --- (In reply to comment #5) > This compiles with no warnings and it seems to work correctly, but I don't > fully understand it: > > > import core.stdc.stdio: printf; > template TypeTuple(TList...) { > alias TList TypeTuple; > } > void main() { > char c = 'b'; > MySwitch: 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"); > } > } > > > Is it correct? if the break inside here is meant to be the foreach break: > { case o: printf("2 %c\n", c); break; } > > Then why a single break is enough after: > > foreach (o; TypeTuple!('b', 'c')) { > case o: printf("2 %c\n", c); break; > } > break; > > despite the foreach synthesizes more than one switch case? Your code is expanded to: void main() { char c = 'b'; switch (c) { case 'a': printf("1 a\n"); break; {case 'b': printf("2 %c\n", c); goto break_foreach;} {case 'c': printf("2 %c\n", c); goto break_foreach;} break_foreach: break; default: printf("default"); } } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 7835] switch case fallthrough error despite a break inside static foreach
http://d.puremagic.com/issues/show_bug.cgi?id=7835 --- Comment #6 from Dmitry Olshansky 2012-04-06 11:37:01 PDT --- (In reply to comment #5) > This compiles with no warnings and it seems to work correctly, but I don't > fully understand it: > > > import core.stdc.stdio: printf; > template TypeTuple(TList...) { > alias TList TypeTuple; > } > void main() { > char c = 'b'; > MySwitch: 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"); > } > } > > > Is it correct? if the break inside here is meant to be the foreach break: Yes. > { case o: printf("2 %c\n", c); break; } No it's {case 0: printf("2 %c\n", c); } the break did his job already, it can't work twice. > > Then why a single break is enough after: > > foreach (o; TypeTuple!('b', 'c')) { > case o: printf("2 %c\n", c); break; > } Then the code below gives you one break after that statement. > break; > > despite the foreach synthesizes more than one switch case? foreach synthesizes exactly one statement here. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 7835] switch case fallthrough error despite a break inside static foreach
http://d.puremagic.com/issues/show_bug.cgi?id=7835 --- Comment #5 from bearophile_h...@eml.cc 2012-04-06 11:32:39 PDT --- This compiles with no warnings and it seems to work correctly, but I don't fully understand it: import core.stdc.stdio: printf; template TypeTuple(TList...) { alias TList TypeTuple; } void main() { char c = 'b'; MySwitch: 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"); } } Is it correct? if the break inside here is meant to be the foreach break: { case o: printf("2 %c\n", c); break; } Then why a single break is enough after: foreach (o; TypeTuple!('b', 'c')) { case o: printf("2 %c\n", c); break; } break; despite the foreach synthesizes more than one switch case? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 7835] switch case fallthrough error despite a break inside static foreach
http://d.puremagic.com/issues/show_bug.cgi?id=7835 bearophile_h...@eml.cc changed: What|Removed |Added Keywords|wrong-code |diagnostic Status|RESOLVED|REOPENED Resolution|INVALID | Summary|Ignored break inside static |switch case fallthrough |foreach |error despite a break ||inside static foreach --- Comment #4 from bearophile_h...@eml.cc 2012-04-06 10:18:05 PDT --- Reopened, because you have missed the error message in my bug report. Using a labeled break: import core.stdc.stdio: printf; template TypeTuple(TList...) { alias TList TypeTuple; } void main() { char c = 'b'; MySwitch: switch (c) { case 'a': printf("1 a\n"); break; foreach (o; TypeTuple!('b', 'c')) { case o: printf("2 %c\n", c); break MySwitch; } default: printf("default"); } } DMD 2.059 beta gives (compiling with -w): test.d(12): Error: switch case fallthrough - use 'goto default;' if intended I have also changed the issue title to better reflect the problem, now the Keywords is 'diagnostic' because it's giving a warning where there is nothing to warn against. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---