[Issue 2925] New: Destructor not called

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat May 2 16:44:54 PDT 2009


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

           Summary: Destructor not called
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: blocker
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: andrei at metalanguage.com


import std.stdio;

struct S {
    this(int x) {
        writefln("this(%s)", x);
        this.x = x;
    }
    this(this) {
        writefln("this(this) with %s", x);
    }
    ~this() {
        writefln("Going away S(%s)", x);
    }
    int x;
}

S fun1() {
    auto s = S(1);
    return s;
}

S fun2() {
    return S(2);
}

void main() {
    //auto s1 = fun1;
    auto s2 = fun2;
}

This example creates two objects but only destroys one. fun1 illustrates the
correct behavior.


-- 



More information about the Digitalmars-d-bugs mailing list