Thread overview
[Issue 7390] Missing switch case fallthrough warning with static foreach
[Issue 7390] Problem in generating switch cases with a static foreach
Apr 24, 2017
Nick Treleaven
Apr 25, 2017
Nick Treleaven
Sep 03, 2018
John Colvin
Dec 17, 2022
Iain Buclaw
April 24, 2017
https://issues.dlang.org/show_bug.cgi?id=7390

Nick Treleaven <nick@geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nick@geany.org

--- Comment #4 from Nick Treleaven <nick@geany.org> ---
(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.

--
April 25, 2017
https://issues.dlang.org/show_bug.cgi?id=7390

Nick Treleaven <nick@geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|rejects-valid               |accepts-invalid
            Summary|Problem in generating       |Missing switch case
                   |switch cases with a static  |fallthrough warning with
                   |foreach                     |static foreach

--
September 03, 2018
https://issues.dlang.org/show_bug.cgi?id=7390

John Colvin <john.loughran.colvin@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |john.loughran.colvin@gmail.
                   |                            |com

--- Comment #5 from John Colvin <john.loughran.colvin@gmail.com> ---
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.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=7390

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P3

--