DIP1000: 'return scope' ambiguity and why you can't make opIndex work
Dennis
dkorpel at gmail.com
Mon Jun 21 16:56:30 UTC 2021
On Monday, 21 June 2021 at 16:10:53 UTC, Dukc wrote:
> With your solution, DIP1000 will prevent the return value of
> `*customPtr` outliving `customPtr`. We would ideally want only
> to prevent `*customPtr` outliving whatever `customPtr.ptr`
> points to, which is what happens now if I understood the table
> right.
That was my first reservation when considering it, but so far I
failed to find a scenario where the `scope` outlives its `ref`.
Take for example this:
```D
@safe:
struct CustomPtr {
private ubyte* ptr;
ubyte* get() return scope {return ptr;}
}
void f(scope ubyte* ptr0) {
scope ubyte* ptr1;
ptr1 = ptr0; // fine
{
CustomPtr c;
c.ptr = ptr0;
ptr1 = c.get(); // scope variable `c` assigned to `ptr1`
with longer lifetime
}
}
```
While ptr0 can be assigned to ptr1, when going through a
`CustomPtr c`, dmd still sees it as assigning "scope variable
`c`".
More information about the Digitalmars-d
mailing list