[Issue 2341] New: Double destruction without intervening copy

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Sep 6 22:02:24 PDT 2008


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

           Summary: Double destruction without intervening copy
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: andrei at metalanguage.com


import std.stdio;

struct A
{
    int id;
    this(int x) { id = x; writeln("Created object from scratch: ", x); }
    this(this) { writeln("Copying object: ", id); }
    ~this() { writeln("Destroying object: ", id); }
}

struct B
{
    A member;
}

B foo()
{
    A a = A(45);
    return B(a);
}

void main()
{
    auto b = foo;
}

The code above prints:
Created object from scratch: 45
Destroying object: 45
Destroying object: 45

Obviously there should be an intervening copy, otherwise the same state gets
destructed twice. The correct output should be:

Created object from scratch: 45
Destroying object: 45
Copying object: 45
Destroying object: 45


-- 



More information about the Digitalmars-d-bugs mailing list