www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21341] New: [REG2.092] Wrong reference escape error when


          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()

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

Happens since dlang 2.092.

Oct 25 2020