The following code:
-----
module evbug;
import std.stdio;
struct S {
int last = 0;
S opCall(int i) {
writefln("%s %s", last, i);
last = i;
return *this;
}
}
void main() {
S t;
t(1)(2);
t(3);
}
-----
should output
=====
0 1
1 2
1 3
=====
(Note that opCall returns a copy of the original struct, so the first and last calls will be passed &t as 'this', but the second is passed a pointer to a copy)
With "dmd -run test.d", this all works fine.
However, when run with "dmd -inline -run test.d":
=====
0 1
1 2
2 3
=====
(note the last line)
The "return *this" seems suddenly to have compiled as a reference return instead of a value return. (This can be verified by making opCall print the address as well; the uninlined version will only report the same address for the first and last call, while the inlined version reports the same address every time)
GDC doesn't exhibit this problem, presumably because it uses the GCC inliner.
Comment #1 by braddr — 2010-05-25T01:59:48Z
Created attachment 642
tentative fix for this for the d2 branch (might work on d1 as well, untested)
This bug exists in the d2 code base as well. This patch fixes the test case and passes the test suite.
Comment #2 by braddr — 2010-05-25T03:05:16Z
Created attachment 643
d2 fix, version 2
Oops.. the version I attached previously was an older copy. This is the newer version that moves the changes down from FuncDeclaration::inlineScan to doInline and fixes a problem with the first version.