digitalmars.D.bugs - [Issue 14246] New: proper destruction of partially constructed
- via Digitalmars-d-bugs (26/26) Mar 04 2015 https://issues.dlang.org/show_bug.cgi?id=14246
https://issues.dlang.org/show_bug.cgi?id=14246 Issue ID: 14246 Summary: proper destruction of partially constructed objects/structs Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: enhancement Priority: P1 Component: DMD Assignee: nobody puremagic.com Reporter: schuetzm gmx.net Currently, when a constructor throws, it will not call destructors of already initialized member fields. The user is responsible for catching exceptions or using `scope(failure)` and cleaning up manually. Of course, this is error prone and can easily be forgotten. I suggest to apply the same heuristic to mutable fields that is also use for tracking the initialization of immutable fields: The first "assignment" to a field must not appear in a loop or after a label, and calls the constructor instead of opAssign(). For immutable and const fields, no further writes are allowed; mutable fields can be changed as desired. At each point where an exception can occur, the compiler is then aware which fields have already been initialized, and can call their destructor. --
Mar 04 2015