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