Fun surprising things

Rubn where at is.this
Thu Nov 1 01:32:27 UTC 2018


On Wednesday, 31 October 2018 at 17:28:43 UTC, Stanislav Blinov 
wrote:
>> So the inconsistency in the spec ("binary expressions are left 
>> to right", "function arguments are implementation defined 
>> order") leaves a gaping hole. What happens when a binary 
>> expression lowers to a function call?
>
> You're misreading the spec. The relevant part is the one I 
> quoted. There's no left-to-right evaluation rule here. It's not 
> a binary expression, it's an argument list; in this case - one 
> argument, which is a CatExpression, which is an 
> AssignExpression, the order of evaluation of it's operands is 
> implementation-defined.

What you quoted only relates to "AssignExpression", that means in 
the following case:

a() += b();

Either a() or b() can be evaluated first, it is not defined.

Ultimately what is being evaluated is:

opBinary!"~"(to!string(a()), to!string(b()));

Which the spec clearly specifies is calculated in left to right 
order:

> Binary expressions are evaluated in strictly left-to-right 
> order. Function arguments are evaluated in strictly 
> left-to-right order for functions with extern (D) linkage.
> 
> assert(text(++i, ++i) == "1415"); // left to right evaluation 
> of arguments



More information about the Digitalmars-d mailing list