[Issue 2127] New: inliner turns struct "return *this" from by-value into by-ref
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat May 24 04:08:16 PDT 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2127
Summary: inliner turns struct "return *this" from by-value into
by-ref
Product: D
Version: 1.030
Platform: PC
OS/Version: All
Status: NEW
Keywords: wrong-code
Severity: major
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: fvbommel at wxs.nl
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.
--
More information about the Digitalmars-d-bugs
mailing list