Bug 19241 – Broken value of auto ref argument for closure

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2018-09-11T09:22:12Z
Last change time
2024-12-13T19:00:30Z
Assigned to
No Owner
Creator
SHOO
Moved to GitHub: dmd#19483 →

Comments

Comment #0 by zan77137 — 2018-09-11T09:22:12Z
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 ------------------- [email protected](9): Assertion failure ---------------- 0x004029B3 in _d_assertp at ...\src\core\exception.d(436) 0x0040225B in _Dmain at main.d(20)
Comment #1 by pro.mathias.lang — 2021-03-01T08:34:12Z
Yeah, `auto ref` is really not a good think when mixed with capture. And unfortunately it's `@safe`.
Comment #2 by robert.schadek — 2024-12-13T19:00:30Z
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