[Issue 19241] New: Broken value of auto ref argument for closure

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 11 09:22:12 UTC 2018


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

          Issue ID: 19241
           Summary: Broken value of auto ref argument for closure
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: zan77137 at nifty.com

This code doesn't work:
-------------------
auto ref run(F, Args...)(F dg, auto ref Args args)
{
    return dg(args);
}
auto makeClosure(alias func, Args...)(auto ref Args args)
{
    auto fptr = args[0].funcptr;
    return {
        // !!!!! Assertion failure !!!!!
        assert(args[0].funcptr is fptr);
        return func(args);
    };
}
auto test(F, Args...)(F dg, auto ref Args args)
{
    return makeClosure!run(dg, args);
}
void main()
{
    auto t = test( delegate ()=> 10 );
    assert(t() == 10);
}
-------------------
dmd -debug -g -run main.d
-------------------
core.exception.AssertError at main.d(9): Assertion failure
----------------
0x004029B3 in _d_assertp at ...\src\core\exception.d(436)
0x0040225B in _Dmain at main.d(20)

--


More information about the Digitalmars-d-bugs mailing list