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

           Summary: [GSoC] Destructor gets called on object before it is
                    copied when calling writeln()
           Product: D
           Version: D2
          Platform: All
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: cristi.cobzare...@gmail.com


--- Comment #0 from Cristi Cobzarenco <cristi.cobzare...@gmail.com> 2011-06-22 
08:46:01 PDT ---
import std.stdio;
import std.conv;

struct Test {
    int x;

    this( int m )     { x = m; }
    this( this )      { writeln( "Postblit: ", x ); }

    ~this()           { x = 42; }

    string toString() { return to!string( x ); }
}

int main(string[] argv) {
    auto a = Test(3);
    writeln( a );
    return 0;
}

When the running the code above, 42 gets printed instead of 3. Looking at the
"Postblit: " writes, one can see that the postblit ctor gets called 6 times and
only the last copy sets x to 42. It seems that at the last copy the destructor
gets called before the object gets blitted.

Using a debugger, I think I found the offending copy at line 1599 in file
format.d. Strangely, as much as I tried to reproduce the same kind of copying,
I could never get the bug to appear without using writeln.

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

Reply via email to