[Issue 15538] wrong code with switch

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Aug 9 08:02:03 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=15538

ag0aep6g at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ag0aep6g at gmail.com
            Summary|final switch statement      |wrong code with switch
                   |raises an exception even    |
                   |though all cases are        |
                   |covered under certain       |
                   |conditions                  |

--- Comment #4 from ag0aep6g at gmail.com ---
Reduced a bit more:

----
struct S
{
    int a = 0;
    int b = 1;
}

int f1(int a)
{
    switch (a)
    {
        case 0: return 10;
        case 1: return 20;
        case 2: return 30;
        case 3: return 40;
        default: return 99;
    }
}

int f2(S s)
{
    return f1(s.a);
}

void main()
{
    S s;
    assert(f1(s.a) == 10); /* passes */
    assert(f2(s) == 10); /* fails */
}
----

(In reply to Sobirari Muhomori from comment #3)
> Does optimization flag -O affect the behavior?

No. -inline has an effect, presumably because f2 is inlined.

--


More information about the Digitalmars-d-bugs mailing list