bug in assigning to dynamic array element

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Sat Nov 1 04:50:25 PDT 2014


On Sat, 01 Nov 2014 11:43:11 +0000
via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> If it's indeed caused by evaluation (which seems likely), then 
> it's not a bug. All expressions are supposed to be evaluated from 
> left to right.
this *IS* a bug. either compiler should error on this, or it shouldn't
modify random memory. imagine the situation when old array contents not
only collected by GC, but that memory was allocated to something
completely different.

and it's completely possible to fix this without dropping evaluation
order promise: take the address of hidden dynamic array structure first
and remember index, and take the address of array element just before
assigning. this way it will work as expected, and will evaluate
all indicies and the array address itself (not the address of the array
contents, but this is irrelevant to evaluation order) first.

what whay authors choose to fix this bug is irrelevant for me (but i
prefer the second way), but it MUST be fixed. either error, or do what
i described in the previous paragraph.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20141101/af7231f6/attachment-0001.sig>


More information about the Digitalmars-d mailing list