More magical AA semantics

monarch_dodra monarchdodra at gmail.com
Fri Jan 11 02:58:59 PST 2013


On Friday, 11 January 2013 at 10:43:33 UTC, Jens Mueller wrote:
> 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.

It is meant to be an lvalue, and is the reason this is legal in 
both C++ and D:

int main()
{
     int a = 0;
     ++++a;
     return 0;
}


More information about the Digitalmars-d mailing list