| |
![Iain Buclaw's Gravatar profile Gravatar of Iain Buclaw](//www.gravatar.com/avatar/17bbd0ceb5389a8803c04834f286731b?d=identicon&s=32) | Posted by Iain Buclaw in reply to Iain Buclaw | Permalink Reply |
|
Iain Buclaw ![Iain Buclaw's Gravatar profile Gravatar of Iain Buclaw](//www.gravatar.com/avatar/17bbd0ceb5389a8803c04834f286731b?d=identicon&s=80)
Posted in reply to Iain Buclaw
| On Thursday, 9 May 2024 at 18:24:12 UTC, Iain Buclaw wrote:
> On Wednesday, 8 May 2024 at 14:26:25 UTC, Paul Backus wrote:
> When the following program is compiled with GDC 14.1, the assertion fails:
void main() {
int d = 42;
bool o = d > d++;
assert(o == false);
}
(Godbolt: https://d.godbolt.org/z/e63xbb9Td)
The assertion passes when the program is compiled with DMD 2.108.0.
The same bug was recently reported for LDC: https://github.com/ldc-developers/ldc/issues/4651
I want to say that rewriting d > d++ to d++ < d is a valid optimization.
See also opCmp rewriting a < b into b.opCmp(a)
https://dlang.org/spec/operatoroverloading.html#compare
Even when it doesn't swap order, DMD doesn't store the left hand of the expression to a target/temporary when operator overloading is involved.
https://d.godbolt.org/z/jYYr1WMhn
o = d.opCmp(d.opUnary!"++"())
Effectively
arg = d.opUnary!"++"(); // d mutates
o = d.opCmp(arg) > 0; // true
|