[Issue 6199] New: [GSoC] Postblit not called when returning a reference to a by-value function.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 23 11:19:01 PDT 2011


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

           Summary: [GSoC] Postblit not called when returning a reference
                    to a by-value function.
           Product: D
           Version: D2
          Platform: All
        OS/Version: Windows
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: cristi.cobzarenco at gmail.com


--- Comment #0 from Cristi Cobzarenco <cristi.cobzarenco at gmail.com> 2011-06-23 11:14:10 PDT ---
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

-- 
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