Bug 7390 – Missing switch case fallthrough warning with static foreach

Status
REOPENED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-01-28T07:06:11Z
Last change time
2024-12-13T17:58:10Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
bearophile_hugs
Moved to GitHub: dmd#18408 →

Comments

Comment #0 by bearophile_hugs — 2012-01-28T07:06:11Z
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 } }
Comment #1 by code — 2012-03-18T10:15:00Z
This seems to be fixed with Bug 6518. *** This issue has been marked as a duplicate of issue 6518 ***
Comment #2 by bearophile_hugs — 2012-03-18T12:43:43Z
I am seeing the case fallthrough error still, on Windows. This bug seems not fixed.
Comment #3 by bearophile_hugs — 2012-03-18T12:55:30Z
To see the wrong error message you need to compile with -w or -wi (confirmed on x86-64 linux too by Zor).
Comment #4 by nick — 2017-04-24T08:52:29Z
(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.
Comment #5 by john.loughran.colvin — 2018-09-03T10:24:33Z
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.
Comment #6 by robert.schadek — 2024-12-13T17:58:10Z
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