I was wondering if this behavior is actually documented anywhere? Let's say we want to increment i and store the new value at the index equal to the new (incremented) value.

        int[int] a;
        int i = 1;
        a[++i] = i;
        writeln(a);
        a[i] = ++i;
        writeln(a);

[2:2]
[2:2, 3:3]

If any, I would expect it to work for either one of lines but not both?

What is interesting, if you compile the same in C (I used clang), you get a "warning: unsequenced modification and access to 'i'" on both lines and the answer is (as I would initially except)

[2:1]
[2:1, 3:3]

Reply via email to