DIP 1021--Argument Ownership and Function Calls--Community Review Round 1
Olivier FAURE
couteaubleu at gmail.com
Wed Jul 31 09:36:20 UTC 2019
On Wednesday, 31 July 2019 at 09:25:26 UTC, Walter Bright wrote:
> On 7/19/2019 9:39 AM, Timon Gehr wrote:
>> @safe:
>> class C{
>> Array a;
>> this(Array a){ this.a=move(a); }
>> }
>>
>> void maybe_bad(C c, ref int i){
>> c.a = Array();
>> i++;
>> }
>>
>> void main(){
>> auto c=new C(Array());
>> c.a.append(5);
>> auto d=c;
>> maybe_bad(c,d.a.get());
>> }
>
> Copying c to d will increase the ref count and so it will be
> safe.
You misread the above example.
c is an instance of a class holding an Array, not an instance of
an Array. So copying c to d doesn't involve calling Array's copy
constructor.
More information about the Digitalmars-d
mailing list