[Issue 9985] Postblit isn't called on local struct return

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Apr 25 04:50:11 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9985



--- Comment #9 from Kenji Hara <k.hara.pg at gmail.com> 2013-04-25 04:50:10 PDT ---
(In reply to comment #8)
> Could you clarify the "This is a compiler bug"? Are you saying this is an
> actual bug according to spec, or just that a "missed optimization opportunity"
> ?

I say "missed optimization opportunity".

> In particular, if I compile using "S" instead of "auto ref", then NRVO only
> triggers in release. However, in non release, postblit still doesn't get
> called.
> 
> This is the correct behavior, correct? In non-release, there is no NRVO, but no
> postblit either, so the code is wrong according to spec?

With git head dmd, `S makeS()` and `auto makeS()` do NRVO. This is expected.
But `auto ref makeS()` doesn't NRVO. This is unexpected and a bug.

> ================
> 
> I also want to note that the "NRVO fix" does not actually fix the original
> code, as passing a temp by value doesn't postblit. This will still fail, even
> in release, even with NRVO:
> 
> //--------
> void doIt(S9985 s)   
> {
>     assert(S9985.ptr == &s); //Passed without postblit, fails here
> 
> }
> void main()
> {
>     doIt(makeS9985());
> }
> //--------

makeS9985 returns an rvalue, and doIt receives the rvalue with 'move'. There is
no copy, so postblit is not called.
And, compiler does not apply NRVO in this case. Non-ref parameter `s` in doIt
function always means that "the given argument is moved in the function". So &s
is always different from S9985.ptr.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list