More magical AA semantics
Jens Mueller
jens.k.mueller at gmx.de
Fri Jan 11 01:01:50 PST 2013
Don wrote:
> Consider this code:
> ---
> int[int] x;
>
> int k = x[2] + 5; // Error, range violation. Makes sense.
>
> x[2] = x[2] + 5; // But this works!!!
> ---
I think the last statement is illegal. Because from
http://dlang.org/expression.html I extract:
The evaluation order of = is implementation defined and it is illegal to
depend on it. The compiler should catch these but it cannot in all
cases. If the evaluation order was fixed i.e. right-to-left in this
case, the code would throw. It also happens that the evaluation may
change depending on the optimization flags.
So I believe it's an issue of evaluation order.
Jens
More information about the Digitalmars-d
mailing list