The following code compiles fine without explicit fall-through, but with -version=bad it errors. int hexStringConstant(dchar* p) { while (1) { dchar c = *p++; switch (c) { case ' ': case '\t': case '\v': case '\f': continue; case '\r': if (*p == '\n') continue; version(bad) /// <-- Look here goto case; case '\n': continue; case 0: case 0x1A: return 111; case '"': return 222; default: break; } } } > dmd -c bug.d [ no problem ] > dmd -c bug.d -w bug.d(18): Warning: switch case fallthrough - use 'goto case;' if intended > dmd -c bug.d -version=bad bug.d(1): Error: function bug.hexStringConstant no return exp; or assert(0); at end of function
DMD version = 2.070.0
I can't get errors nor warnings for fallthroughs except with final switches on enums (-w or -wi don't help). Compiler versions: - DMD64 D Compiler v2.082.0 - nightly at https://run.dlang.io/ import std.stdio; void main() { int x = 0; switch (x) { case 0: case 1: writeln("woot"); return; default: } }
Actually I don't get fallthrough warnings for *any* switches.
So it seems to accept *empty* cases to fall through. I guess this is intended, then?
When compiling the initial example I get: test.d(18): Error: switch case fallthrough - use 'goto case;' if intended This seems to have been fixed
(In reply to RazvanN from comment #5) > When compiling the initial example I get: > > test.d(18): Error: switch case fallthrough - use 'goto case;' if intended > > > This seems to have been fixed The problem is that with -version=bad, it incorrectly raises an error about missing a return statement or assert(0). That's still the case. Here's a reduced example: ``` // accepts valid int a() { while (1) { switch (0) { case 0: // < implicit fallthrough default: continue; } } } // rejects valid int b() { while (1) { switch (0) { case 0: goto default; // < explicit fallthrough default: continue; } } } ```
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19101 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB