On 21 October 2013 21:41, Timon Gehr <[email protected]> wrote: > On 10/21/2013 10:32 PM, Iain Buclaw wrote: >> >> On 21 October 2013 21:24, Timon Gehr <[email protected]> wrote: >>> >>> On 10/21/2013 07:53 PM, Iain Buclaw wrote: >>>> >>>> >>>> On 21 October 2013 18:42, Walter Bright <[email protected]> >>>> wrote: >>>>> >>>>> >>>>> On 10/21/2013 9:24 AM, Iain Buclaw wrote: >>>>>> >>>>>> >>>>>> >>>>>> http://dpaste.dzfl.pl/3e333df6 >>>>>> >>>>>> PS: Walter, looks the above causes an ICE in DMD? >>>>> >>>>> >>>>> >>>>> >>>>> All ICE's should be filed in bugzilla: >>>>> >>>>> http://d.puremagic.com/issues/show_bug.cgi?id=11315 >>>>> >>>> >>>> I've told enough people to raise bugs in GDC to know this. My >>>> intention wasn't to find a bug in DMD though when I pasted that link. >>>> ;-) >>>> >>>> I was more curious what LDC does if it stack allocates array literals >>>> assigned to static arrays in that program. My guess is that the >>>> dynamic array will get the address of the stack allocated array >>>> literal, and it's values will be lost after calling fill(); >>>> >>>> If so, this is another bug that needs to be filled and fixed. >>>> >>> >>> Why? AFAICS it is the expected behaviour in any case. >> >> >> It's an assignment to a dynamic array, so it should invoke the GC and >> do a _d_arraycopy. >> >> > > This code: > > int[] x; > int[3] y; > > x = y = [1,2,3]; > > Is equivalent to this code: > > int[] x; > int[3] y; > > y = [1,2,3]; > x = y; // <-- here > > Are you saying the line marked with "here" should perform an implicit > allocation and copy the contents of y to the heap? > >
In GDC, the allocation currently is: y = [1,2,3]; // <--- here So it is a safe to not copy. But yes. I think a GC memcopy should be occuring, as dynamic arrays aren't passed by value, so are expected to last the lifetime of the reference to the address. -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0';
