[Issue 21341] New: [REG2.092] Wrong reference escape error when parameter is stored in this

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Oct 25 12:58:34 UTC 2020


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 at puremagic.com
          Reporter: johanengelen at 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.

--


More information about the Digitalmars-d-bugs mailing list