Bug 6199 – [GSoC] Postblit not called when returning a reference to a by-value function.

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-06-23T11:14:00Z
Last change time
2012-05-10T19:53:28Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
cristi.cobzarenco

Comments

Comment #0 by cristi.cobzarenco — 2011-06-23T11:14:10Z
Code: import std.stdio; struct Test { this( this ) { writeln( "postblit" ); } ~this() { writeln( "destroyed" ); } } void takesVal( Test x ) {} ref Test returnsRef( ref Test x ) { return x; } int main() { Test x; takesVal( returnsRef( x ) ); return 0; } -------------- Output: destroyed destroyed So while there is copy getting destroyed, the postblit doesn't get called. The code works fine when passing a ref argument: Code: [...] void f( ref Test x ) { takesVal( x ); } int main() { Test x; f( x ); } -------------- Output: postblit destroyed destroyed This bug is probably related to http://d.puremagic.com/issues/show_bug.cgi?id=5737
Comment #1 by lovelydear — 2012-04-24T11:43:49Z
Bug is confirmed with 2.059
Comment #2 by lovelydear — 2012-05-04T23:01:01Z
See also related issue 5737 and issue 8045
Comment #3 by k.hara.pg — 2012-05-04T23:32:00Z
Comment #4 by github-bugzilla — 2012-05-07T18:10:39Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/9c03f1445966163321cf40456f35f83f534f2b1a fix Issue 6199 - [GSoC] Postblit not called when returning a reference to a by-value function. https://github.com/D-Programming-Language/dmd/commit/7f18602f38082d8b837112fed1d5d10b222e3b87 Merge pull request #927 from 9rnsr/fix_postblit Issue 5737 & 6199 - fix postblit call with ref return
Comment #5 by k.hara.pg — 2012-05-10T19:53:28Z
*** Issue 6257 has been marked as a duplicate of this issue. ***