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]);