[Issue 22522] [dip1000] Creating interior pointers allowed in @safe

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 15 17:18:51 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=22522

Dennis <dkorpel at live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|WONTFIX                     |---

--- Comment #5 from Dennis <dkorpel at live.nl> ---
(In reply to Walter Bright from comment #4)
> The error message isn't great, but it is correctly identifying the problem.

It's saying `this` has longer lifetime than `this`. Since when does `x > x`
evaluate to true?

It also still works when you add `return scope` to the constructor:
```
@safe:
struct S {
    int storage;
    int* ptr;

    this(int dummy) return scope {
        ptr = &storage;
    }

    int* get() return scope {
        return ptr;
    }
}

int* escape() {
    S s = S(0);
    return s.get; // escapes a pointer to stack variable `s`
}
```

--


More information about the Digitalmars-d-bugs mailing list