D needs first-class lifetimes before it can get ownership and borrowing

Olivier FAURE couteaubleu at gmail.com
Sat Aug 10 23:41:57 UTC 2019


On Saturday, 10 August 2019 at 16:48:26 UTC, Dennis wrote:
> If I change it to:
> ```
> void borrow() scope { gptr = this.ptr; }
> ```
>
> I get:
> ```
> Error: scope variable this assigned to non-scope gptr
> ```

... Huh.

Okay, this is... interesting. I'm not finding obvious holes 
either (though I wonder if you can game it by having a 
SmartPtr!SmartPtr). Too bad the semantics for combining ref and 
scope in dip1000 aren't documented.

> I don't know why it compiles without scope though.

Because without scope, borrow takes ref this, and with scope, it 
takes ref scope this.

Similarly, foo(ref scope int*) and foo(scope int**) have 
different semantics.

I need to tweak with this. My understanding is that ref scope is 
a special case where the language enforces lifetime on two levels 
instead of the default one, so this might be enough to cobble 
together a working OB system.


More information about the Digitalmars-d mailing list