bug : consecutive function calls and -inline
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Sat May 24 04:08:39 PDT 2008
noob-is-noob wrote:
> sorry if it has been discussed.
> ===code===
> module evbug ;
> import std.stdio ;
>
> struct S(T) {
> T[] arr ;
> S!(T) opCall(T a) {
> arr ~= a ;
> writefln("%s ", arr) ;
> return *this ;
> }
> }
>
> void main() {
> S!(string) t ;
> t("AAA")("BBB")("CCC") ;
> t("<-result") ;
> }
> ===output=== v2.014 (similar result for v1.030)
> 1/ compiled with -inline, ok:
> [AAA]
> [AAA BBB]
> [AAA BBB CCC]
> [AAA BBB CCC <-result]
>
> 2/ compiled w/o -inline, ng:
> [AAA]
> [AAA BBB]
> [AAA BBB CCC]
> [AAA <-result]
This definitely looks like a bug to me. However, the second behavior
(w/o -inline) is the correct one. opCall returns a *copy* of the struct
it's called on, so only the initial call in each sequence should modify
the original. The other two should modify copies. That means only "AAA"
and "<-result" should be in t.arr at the end of main().
Since GDC gets this right, it's probably a bug in the DMD inliner.
I've entered this into bugzilla:
<http://d.puremagic.com/issues/show_bug.cgi?id=2127>
More information about the Digitalmars-d-learn
mailing list