digitalmars.D.bugs - [Issue 21341] New: [REG2.092] Wrong reference escape error when
- d-bugmail puremagic.com (42/42) Oct 25 2020 https://issues.dlang.org/show_bug.cgi?id=21341
https://issues.dlang.org/show_bug.cgi?id=21341 Issue ID: 21341 Summary: [REG2.092] Wrong reference escape error when parameter is stored in this Product: D Version: D2 Hardware: x86 OS: Mac OS X Status: NEW Severity: regression Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: johanengelen weka.io ``` struct A { bool delegate() dlg; } struct Watcher { bool b; bool func() const { return b; } } struct S { A[] watchers; void registerWatcher(return ref Watcher watcher) { watchers ~= A(&watcher.func); // line 13 } } S s; Watcher watcher; void foo() { s.registerWatcher(watcher); } ``` Compile with `-w de` and it shows a wrong deprecation message: <source>(13): Deprecation: copying `A(&watcher.func)` into allocated memory escapes a reference to parameter variable `watcher` The `return` on parameter `watcher` means that the reference escapes to the `this` parameter. See spec 19.6.5.4. Happens since dlang 2.092. --
Oct 25 2020