DIP77 - Fix unsafe RC pass by 'ref'

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 10 20:21:34 PDT 2015


On 4/10/2015 2:50 PM, Michel Fortin wrote:
> And how is it pinned in this case?
>
>   struct S {
>       private RCArray!T array;
>       ref T opIndex(int index) return { return array[index]; }
>       void clear() { s.array = RCArray!T([]); }
>   }
>   void main() {
>       auto s = S(RCArray!T([T()])); // s.array's refcount is now 1
>       foo(s, s[0]);           // pass by ref

The s[0] is preceded by tmp=s; Because T is reachable from typeof(first argument s)

>   }
>   void foo(ref S s, ref T t) {
>       s.clear();            // drop the old s.array
>       t.doSomething();              // oops, t is gone
>   }
>



More information about the Digitalmars-d mailing list