[Issue 14246] New: proper destruction of partially constructed objects/structs
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Mar 4 11:23:55 PST 2015
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 at puremagic.com
Reporter: schuetzm at 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.
--
More information about the Digitalmars-d-bugs
mailing list