bug in assigning to dynamic array element

Iain Buclaw via Digitalmars-d digitalmars-d at puremagic.com
Sat Nov 1 04:54:31 PDT 2014


On 1 November 2014 11:31, anonymous via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On Saturday, 1 November 2014 at 09:03:42 UTC, ketmar via
> Digitalmars-d wrote:
>>
>> as i can guess, the bug is in evaluating left part of '=' operation
>> before the right part.
>
>
> I don't know how D defines this, and I couldn't find anything but
> a forum discussion [1] (which I didn't read all of). But unless
> it's explicitly stated that the right-hand side is evaluated
> first, there is no bug.
>
> A simpler test case:
>

Breakdown.

>      auto list = new size_t[1];

list = addressA;

>      list[0] = (){list = new size_t[1]; return 666;}();

list = addressB;
addressA[0] = 666;

>      assert(list[0] == 666);

assert(addressB[0] == 666)


More information about the Digitalmars-d mailing list