DIP1000: Scoped Pointers (Discussion)

Kagamin via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 12 06:27:08 PDT 2016


On Thursday, 11 August 2016 at 21:57:06 UTC, Walter Bright wrote:
>> auto arr = RefCountedSlice!int(10);
>> auto ptr = &arr[5];
>> arr = RefCountedSlice!int(42);
>> *ptr = 1;    // use after free
>
> The idea is to have containers return references by 'return 
> ref' or 'return scope' so the internal references can't escape 
> the expression they're used in.

What expressions are allowed? Will this work?

auto arr = RefCountedSlice!int(10);
void f(scope ref int n)
{
   arr = RefCountedSlice!int(42);
   n = 1; // use after free
}
f(arr[5]);


More information about the Digitalmars-d mailing list