D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19241 - Broken value of auto ref argument for closure
Summary: Broken value of auto ref argument for closure
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-11 09:22 UTC by SHOO
Modified: 2024-12-13 19:00 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description SHOO 2018-09-11 09:22:12 UTC
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@main.d(9): Assertion failure
----------------
0x004029B3 in _d_assertp at ...\src\core\exception.d(436)
0x0040225B in _Dmain at main.d(20)
Comment 1 Mathias LANG 2021-03-01 08:34:12 UTC
Yeah, `auto ref` is really not a good think when mixed with capture. And unfortunately it's `@safe`.
Comment 2 dlangBugzillaToGithub 2024-12-13 19:00:30 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19483

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB