This seems related to bug 6518 Generating switch cases with a static foreach gives some problems still (DMD 2.058head): import std.typetuple: TypeTuple; void main() { char c; switch (c) { // OK case 'z': break; case 'x': break; case 'y': break; default: break; } alias TypeTuple!('x', 'y') xy; switch (c) { // OK foreach (X; xy) { case X: break; } default: break; } switch (c) { case 'z': break; foreach (X; xy) { case X: break; } default: break; // Error: switch case fallthrough } }
This seems to be fixed with Bug 6518. *** This issue has been marked as a duplicate of issue 6518 ***
I am seeing the case fallthrough error still, on Windows. This bug seems not fixed.
To see the wrong error message you need to compile with -w or -wi (confirmed on x86-64 linux too by Zor).
(In reply to bearophile_hugs from comment #0) > switch (c) { // OK > foreach (X; xy) { > case X: break; > } > default: break; > } The foreach break line above should error, this seems to be the bug. Still present with 2.074. > switch (c) { > case 'z': break; > foreach (X; xy) { > case X: break; > } > default: break; // Error: switch case fallthrough > } > } This is correct.
Another simple example: void main() { import std.stdio; import std.meta; switch (0) { foreach (i; AliasSeq!(0, 1)) { case i: writeln(i); } default: writeln("other"); } } Compiles fine without deprecations or warnings. This has caught me out multiple times as I expect D to stop me making this mistake.
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18408 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB