Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken value of auto ref argument for closure #19483

Open
dlangBugzillaToGithub opened this issue Sep 11, 2018 · 1 comment
Open

Broken value of auto ref argument for closure #19483

dlangBugzillaToGithub opened this issue Sep 11, 2018 · 1 comment

Comments

@dlangBugzillaToGithub
Copy link

SHOO (@shoo) reported this on 2018-09-11T09:22:12Z

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

CC List

Description

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)
@dlangBugzillaToGithub
Copy link
Author

pro.mathias.lang (@Geod24) commented on 2021-03-01T08:34:12Z

Yeah, `auto ref` is really not a good think when mixed with capture. And unfortunately it's `@safe`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant