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)
Yeah, `auto ref` is really not a good think when mixed with capture. And unfortunately it's `@safe`.
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