D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7390 - Missing switch case fallthrough warning with static foreach
Summary: Missing switch case fallthrough warning with static foreach
Status: REOPENED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2012-01-28 07:06 UTC by bearophile_hugs
Modified: 2024-12-13 17:58 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2012-01-28 07:06:11 UTC
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 Martin Nowak 2012-03-18 10:15:00 UTC
This seems to be fixed with Bug 6518.

*** This issue has been marked as a duplicate of issue 6518 ***
Comment 2 bearophile_hugs 2012-03-18 12:43:43 UTC
I am seeing the case fallthrough error still, on Windows. This bug seems not fixed.
Comment 3 bearophile_hugs 2012-03-18 12:55:30 UTC
To see the wrong error message you need to compile with -w or -wi  (confirmed on x86-64 linux too by Zor).
Comment 4 Nick Treleaven 2017-04-24 08:52:29 UTC
(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 John Colvin 2018-09-03 10:24:33 UTC
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 dlangBugzillaToGithub 2024-12-13 17:58:10 UTC
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