D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6552 - Wrong fallthrough warning for CaseRange
Summary: Wrong fallthrough warning for CaseRange
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 normal
Assignee: Andrej Mitrovic
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2011-08-24 19:30 UTC by timon.gehr
Modified: 2022-04-09 20:50 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description timon.gehr 2011-08-24 19:30:48 UTC
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 SomeDude 2012-04-27 09:58:55 UTC
Compiles on 2.059
Comment 2 timon.gehr 2012-04-27 10:29:09 UTC
No, it does not. Check again with the correct compiler options. (you need -w)
Comment 3 SomeDude 2012-04-27 15:07:07 UTC
Allright, I overlooked your comment.
Comment 4 Andrej Mitrovic 2013-02-17 13:47:59 UTC
https://github.com/D-Programming-Language/dmd/pull/1673
Comment 5 Stewart Gordon 2013-02-17 17:33:51 UTC
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 Andrej Mitrovic 2013-02-17 17:43:36 UTC
(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 Stewart Gordon 2013-02-17 18:07:37 UTC
Where is the separate bug report about the spec being wrong?
Comment 8 Kenji Hara 2013-02-17 18:29:26 UTC
(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 github-bugzilla 2013-02-17 19:34:01 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/cac04a3dd38741205cac6b61400a7f91a8c8a36a
Fixes Issue 6552 - Invalid error on non-existent switch-case fallthrough.

https://github.com/D-Programming-Language/dmd/commit/631e980d134d7217ac3fe43809b625bc8f5bff9f
Merge pull request #1673 from AndrejMitrovic/Fix6552

 Issue 6552 - Invalid warning on non-existent switch case fallthrough.