[Issue 9985] Postblit isn't called on local struct return
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Apr 24 13:13:59 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9985
monarchdodra at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |monarchdodra at gmail.com
--- Comment #1 from monarchdodra at gmail.com 2013-04-24 13:13:57 PDT ---
This is not a bug, but a feature.
D has very efficient move semantics, in particular [N]RVO, because D stipulates
that stack objects may be *moved* without calling postblits.
One of the corollaries to this is that internal pointers are pointers to self
are not accepted as legal code in D, and (as you have noticed) breaks the
program.
Note that your second program exhibits the same behavior: you merely added an
extra copy wich triggers the postblit. You have an intermediary temporary.
Rule of thumb is that you usually don't need internal pointers anyways. If you
absolutely can't do without it, construct your object into a specific place,
and *then* connect the pointers.
I'll close this if the explanation is okay with you.
--
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