On 02/13/12 21:52, Jonathan M Davis wrote: > On Monday, February 13, 2012 21:49:05 Artur Skawina wrote: >> "argument evaluation" in this context means that given eg "f(a,b,c);" >> it's not specified in what order the expressions 'a', 'b', and 'c' >> are evaluated, which matters if they are dependent or have side >> effects. (depending on arg passing conventions it can make sense to >> implement this one way or the other). If an expression is specced >> as l-t-r (as CatExpression is here) then the call to foo() must >> happen before executing bar(); the operator only comes into play later. > > Ideally perhaps, but I expect that that's not true, because operator > overloading is done via lowering. > > foo() ~ bar() > > would become > > opBinary!"~"(foo(), bar()); > > which is a normal function call. It's possible that the compiler always > evaluates foo first, but I'd seriously advise against relying on it. > > In the long run, it probably will be guaranteed, because Walter wants to make > it so that function arguments are always evaluated left-to-right, but until > that happens, I wouldn't bet on foo() ~ bar() being guaranteed to have foo > called before bar, even it's supposed to be.
The important thing here is - the order absolutely *must* be foo(), then bar(), what happens under the hood is completely irrelevant. The reason is simple - if this is not what happens then it's a serious compiler bug. And if you can't rely on the order then it just shouldn't be documented. The order /could/ be undefined, so specifying it means the programmer has to assume he/she /can/ count that the compiler follows it - otherwise defining it wouldn't make any sense. IOW having the order defined, but not implemented, causes bugs that wouldn't be there without such definition; hence one has to assume that it *is* implemented (modulo unknown compiler bugs of course). Undefining the order is a much better solution than suggesting that users should assume the compiler is broken. It can always be re-defined later, switching from defined to undefined is not as easy. artur