On Monday, 19 May 2014 at 08:20:54 UTC, Namespace wrote:
On Sunday, 18 May 2014 at 22:29:04 UTC, bearophile wrote:
"Undefined Behavior in C++; what is it, and why should I
care":
https://github.com/boostcon/cppnow_presentations_2014/blob/master/files/Undefined-Behavior.pdf?raw=true
This reminds us to remove as much undefined behavior as
possible from D.
Fixing some of those problems will break some D code. An
example from the slides pack:
void main() {
import std.stdio;
auto arr = [0, 2, 4, 6, 8];
int i = 1;
writeln(i + arr[++i] + arr[i++]);
}
dmd is right, so ldc has probably a bug.
i is 1
++i is 2 -> arr[2] is 4
i++ is still 2 -> arr[2] is 4
1 + 4 + 4 = 9
Addition does not imply an order in D, does it? So, the following
lines should be equivalent:
writeln(i + arr[++i] + arr[i++]);
writeln(arr[++i] + i + arr[i++]);
writeln(arr[i++] + i + arr[++i]);
writeln(i + arr[i++] + arr[++i]);
Your reasoning step "is still 2" is inapplicable when there is no
order.