On 24/05/2016 14:48, Nick Treleaven wrote:
On Monday, 23 May 2016 at 17:03:32 UTC, Marc Schütz wrote:
On Monday, 23 May 2016 at 15:18:51 UTC, Nick Treleaven wrote:
I think the reason D doesn't support local refs is because it would
make it harder to design @safe, particularly with the planned @rc
ref-counting.
They wouldn't pose a problem for lifetime tracking,
because they can never be assigned to, only initialized once.

What about:

@safe unittest
{
     RCArray!int arr;
+      arr.length = 1;
     ref r = arr[0];
     arr.destroy; // refcount drops to zero, arr.impl memory freed
     r++; // writes to unallocated memory
}

Here I think local refs must be prevented from initialization by return ref (-dip25). The @rc DIP and RCArray would use return ref. It would be OK to initialize a local ref with a ref function result that is not return ref. Naturally, this would be @safe:

auto slice = [7];
ref r = slice[0];
slice.destroy;
r++; // slice memory still allocated

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

Reply via email to