More on C++ stack arrays

Timon Gehr timon.gehr at gmx.ch
Mon Oct 21 13:41:06 PDT 2013


On 10/21/2013 10:32 PM, Iain Buclaw wrote:
> On 21 October 2013 21:24, Timon Gehr <timon.gehr at gmx.ch> wrote:
>> On 10/21/2013 07:53 PM, Iain Buclaw wrote:
>>>
>>> On 21 October 2013 18:42, Walter Bright <newshound2 at digitalmars.com>
>>> 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?




More information about the Digitalmars-d mailing list