[Issue 13661] New: static array init does not call destructors

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Oct 27 01:31:25 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=13661

          Issue ID: 13661
           Summary: static array init does not call destructors
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: shachar at shemesh.biz

Please consider the following program:

import std.stdio;

struct S {
    int x;

    this(this) {
        writeln("this(this)");
    }

    ~this() {
        writeln("~this()", &this, " ", x);
    }

    ref auto opAssign(T)(T arg) {
        x = arg.x;
        writeln("opAssign ", T.stringof, " x=", x);
        return this;
    }
}

void main() {
    S[2] a;
    S[2] b;

    a[0].x = 12;
    a[1].x = 17;

    // a = b;           // 1
     a = a.init;      // 2
    // a[] = S.init;    // 3

    writeln("end a=", a[0].x, ", ", a[1].x);
}

At no point is a destructor called for x=12 or x=17. No opAssign is called at
all.

Replacing the line marked "2" with either "1" or "3" works just fine.

This is a major blocker for implementing RAII type resource management.

--


More information about the Digitalmars-d-bugs mailing list