Bug 10972 – aggregate postblit doesn't clean up in case of failure

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-05T07:26:00Z
Last change time
2015-06-17T21:01:38Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
monarchdodra

Comments

Comment #0 by monarchdodra — 2013-09-05T07:26:20Z
Structs will not recursively destroy their members if the construction scheme fails: //#### import std.stdio; struct A { this(this) {writeln("copied A");} ~this() {writeln("destroy A");} } struct B { this(this) { writeln("B says what?"); throw new Exception("BOOM!"); } ~this() {writeln("destroy B");} } struct S { A a; B b; } void main() { S s1; S s2; writeln("----"); try s2 = s1; catch {} writeln("----"); try S s3 = s1; catch {} writeln("----"); } //#### ---- copied A B says what? ---- copied A B says what? ---- destroy B destroy A destroy B destroy A //#### Be it CC, or "postblit-based" assignment, first, the "A" element is constructed, the B fails to CC, but the first A is never actually destroyed. Postblit should first destroy all created members before propagating the exception. This should be pretty standard and expected behavior for struct construction. The irony is that only static arrays handle this correctly, but only because they have their own (arguably weird) construction scheme.
Comment #1 by k.hara.pg — 2015-03-06T14:08:22Z
Comment #2 by github-bugzilla — 2015-03-31T01:21:06Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f12af1807c84dc47ece6b53b26541d01428c45cd fix Issue 10972 - aggregate postblit doesn't clean up in case of failure https://github.com/D-Programming-Language/dmd/commit/4e811cba25f0f7e51d1b686c893030bc4b8ab2fb Merge pull request #4456 from 9rnsr/fix10972 Issue 10972 - aggregate postblit doesn't clean up in case of failure
Comment #3 by github-bugzilla — 2015-06-17T21:01:38Z