[Issue 7835] switch case fallthrough error despite a break inside static foreach
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue May 12 09:00:16 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=7835
Alex Parrill <initrd.gz at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |initrd.gz at gmail.com
--- Comment #11 from Alex Parrill <initrd.gz at gmail.com> ---
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.
--
More information about the Digitalmars-d-bugs
mailing list