DIP77 - Fix unsafe RC pass by 'ref'
Martin Nowak via Digitalmars-d
digitalmars-d at puremagic.com
Fri Apr 10 14:11:54 PDT 2015
On 04/09/2015 01:10 AM, Walter Bright wrote:
> http://wiki.dlang.org/DIP77
In the first problem example:
struct S {
RCArray!T array;
}
void main() {
auto s = S(RCArray!T([T()])); // s.array's refcount is now 1
foo(s, s.array[0]); // pass by ref
}
void foo(ref S s, ref T t) {
s.array = RCArray!T([]); // drop the old s.array
t.doSomething(); // oops, t is gone
}
What do you do to pin s.array?
auto tmp = s;
or
auto tmp = s.array;
More information about the Digitalmars-d
mailing list