void main() {
int c;
switch (c) {
case 1,2:
case 3,4: break;
default: break;
}
}
Compile with warnings on, DMD v2.054:
tt.d(12): Error: switch case fallthrough - use 'goto case;' if intended
This warning is wrong.
For comparison, the equivalent code without CaseRanges passes even with warnings on:
void main() {
int c;
switch (c) {
case 1:
case 2: break;
default: break;
}
}
Comment #1 by lovelydear — 2012-04-27T09:58:55Z
Compiles on 2.059
Comment #2 by timon.gehr — 2012-04-27T10:29:09Z
No, it does not. Check again with the correct compiler options. (you need -w)
Comment #3 by lovelydear — 2012-04-27T15:07:07Z
Allright, I overlooked your comment.
Comment #4 by andrej.mitrovich — 2013-02-17T13:47:59Z
The code is not valid per the current spec.
http://dlang.org/statement.html#SwitchStatement
CaseStatement:
case ArgumentList : ScopeStatementList
ScopeStatementList:
StatementListNoCaseNoDefault
StatementListNoCaseNoDefault:
StatementNoCaseNoDefault
StatementNoCaseNoDefault StatementListNoCaseNoDefault
By this spec,
case 1,2: case 3,4: anything
is invalid.
Comment #6 by andrej.mitrovich — 2013-02-17T17:43:36Z
(In reply to comment #5)
> The code is not valid per the current spec.
>
> http://dlang.org/statement.html#SwitchStatement
>
> CaseStatement:
> case ArgumentList : ScopeStatementList
>
> ScopeStatementList:
> StatementListNoCaseNoDefault
>
> StatementListNoCaseNoDefault:
> StatementNoCaseNoDefault
> StatementNoCaseNoDefault StatementListNoCaseNoDefault
>
> By this spec,
> case 1,2: case 3,4: anything
> is invalid.
I already said the spec was wrong and will have to be fixed. The OP code works without -w, and we're not about to break a ton of code because the spec is outdated (which is *very* common).
Comment #7 by smjg — 2013-02-17T18:07:37Z
Where is the separate bug report about the spec being wrong?
Comment #8 by k.hara.pg — 2013-02-17T18:29:26Z
(In reply to comment #7)
> Where is the separate bug report about the spec being wrong?
Opened.
Issue 9529 - Switch Statement grammar bug for the chain of case statements
Comment #9 by github-bugzilla — 2013-02-17T19:34:01Z