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

--- Comment #3 from Rainer Schuetze <r.sagita...@gmx.de> ---
Here's a version without lazy and templates:

import core.exception;

Exception collectExceptionE(int delegate () expression, ref int result)
{
    try
    {
        result = expression();
    }
    catch (Exception e)
    {
        return e;
    }
    return null;
}

RangeError collectExceptionR(int delegate () expression, ref int result)
{
    try
    {
        result = expression();
    }
    catch (RangeError e)
    {
        return e;
    }
    return null;
}

void main()
{
    int b;
    int foo() { throw new Exception("blah"); }
    assert(collectExceptionE(&foo, b));

    int[] a = new int[3];
    int goo() { return a[4]; }
    collectExceptionR(&goo, b);
}

I suspect that the functions need to be the exact same code, and only the
associated exception data differs. That's also why you cannot easily eliminate
the delegate call.

Please note that you have to remove /OPT:NOICF from sc.ini to reproduce, as it
was added as a workaround.

--

Reply via email to