Order of evaluation of a += a++;

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 30 20:49:41 PDT 2015


On Tuesday, 31 March 2015 at 01:01:24 UTC, Andrei Alexandrescu 
wrote:
> On 3/30/15 5:49 PM, deadalnix wrote:
>> Why are you doing the replacement top/down rather than bottom 
>> up ?
>
> What would be the alternative? -- Andrei

Doing the replacement bottom up :

a = a++;

a += { auto olda = a; a = a + 1; return olda; }();

a = cast(typeof(a)) (a + { auto olda = a; a = a + 1; return olda; 
}());

Other code transformation do not require a function call to take 
place, so why would this require one (which force eager 
evaluation of parameters) ?

That is also inconsistent with LTR evaluation. On the other hand, 
that would make behavior consistent with what opOpAssign would 
give, so why not.


More information about the Digitalmars-d mailing list