More magical AA semantics

Jens Mueller jens.k.mueller at gmx.de
Fri Jan 11 02:43:22 PST 2013


deadalnix wrote:
> On Friday, 11 January 2013 at 10:16:28 UTC, Jens Mueller wrote:
> >deadalnix wrote:
> >>On Friday, 11 January 2013 at 08:55:55 UTC, Bernard Helyer
> >>wrote:
> >>>I completely agree. Doesn't the spec say that relying on
> >>>the order of assignment evaluation is undefined?
> >>
> >>After a long discussion with Andrei, it seems that it is left to
> >>right.
> >
> >Then the spec should be fixed.
> >
> >unittest
> >{
> >	int a = 0;
> >	++a = a;
> >	assert(a == 1);
> >}
> >
> 
> ++a isn't supposed to be an lvalue (it is not assignable).

Really? I thought the semantics (of ++a) are increment a and return a
reference to it. Whereas a++ is rewritten to (auto t = e, ++e, t). That
means it returns a copy of the old value of a.

> >Don't know though whether you find it surprising that the above
> >code
> >passes? But whether it is left to right or right to left does not
> >matter
> >that much. At least it's defined and you can internalize it.
> >The more I think about the more sense it makes to have it left to
> >right.
> >
> 
> It shouldn't pass as the entry has never been assigned when
> computing the value.

Isn't this a speciality of AAs in D/C++? When you access an non existing
element it gets created? You do not need to assign to it.

Jens


More information about the Digitalmars-d mailing list