What    |Removed                     |Added
                 CC|                            |

--- Comment #1 from 2010-05-02 18:47:49 PDT ---
Here is a somewhat reduced test case:
class Parent {
    this( Object c ) { assert(false, "a"); }
    ~this() { assert( false, "b" ); }

Object foo() { throw new Exception( "Some error" ); }

void main() {
    try {
        auto parent = new Parent( foo() );
    } catch (Exception e) {

This fails with assertion b (the dtor), even though the constructor (assertion
a) was never called.

Disassembly proves that a new object is allocated, before foo() and the ctor of
Parent is called. Possible solutions:
- allow the runtime to run the dtor/finalizer only if the ctor was called (set
a flag immediately before calling the ctor or so)
- allocate the object only immediately before calling the ctor

I'm not sure if Walter would agree that this is a bug. The dtor gets called
even if the ctor fails by throwing an exception. In general, the user has to be
very careful with finalizers: using finalizers is full of synchronization
issues, trouble caused by not being allowed to access references, and so on.
Basically a programmer's trap.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to