Bug 13661 – static array init does not call destructors

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-10-27T08:31:00Z
Last change time
2015-02-18T03:40:04Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
shachar

Comments

Comment #0 by shachar — 2014-10-27T08:31:25Z
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.
Comment #1 by tomer — 2014-10-27T18:27:58Z
Comment #2 by k.hara.pg — 2014-10-31T19:17:07Z
Comment #3 by github-bugzilla — 2014-11-20T11:02:11Z
Commits pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/c4ec102cd63c76ffd27e40a2ab0795cd73ed6d07 fix Issue 13661 - static array init does not call destructors Add internal functions to handle assignment from an array with rvalue elements. https://github.com/D-Programming-Language/druntime/commit/2a3f73c391bd652f34f14f3cc013e37ed6359290 Merge pull request #1006 from 9rnsr/fix13661 Issue 13661 - static array init does not call destructors
Comment #4 by github-bugzilla — 2014-11-23T03:13:04Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/36ef68192330595296e783bc45ca55aabf90c40c fix Issue 13661 - static array init does not call destructors https://github.com/D-Programming-Language/dmd/commit/4aeb77189e665374ec79b85429123c63e27199cc Merge pull request #4100 from 9rnsr/fix13661 Issue 13661 - static array init does not call destructors
Comment #5 by github-bugzilla — 2015-01-25T00:11:38Z
Comment #6 by github-bugzilla — 2015-02-18T03:38:12Z
Comment #7 by github-bugzilla — 2015-02-18T03:40:04Z