Title
Destructors, exceptions, and deallocation
Status
dup
Section
7.6.2.9 [expr.delete]
Submitter
Mike Miller

Created on 2000-11-21.00:00:00 last changed 189 months ago

Messages

Date: 2008-10-15.00:00:00

Rationale (October, 2008):

It was noticed that issue 353, an exact duplicate of this one, was independently opened and resolved.

Date: 2001-04-15.00:00:00

Notes from 04/01 meeting:

There is a widespread feeling that it is a poor programming practice to allow destructors to terminate with an exception (see issue 219). This question is thus viewed as a tradeoff between efficiency and supporting "bad code." It was observed that there is no way in the current language to protect against a throwing destructor, since the throw might come from a virtual override.

It was suggested that the resolution to the issue might be to make it implementation-defined whether the storage is freed if the destructor throws. Others suggested that the Standard should require that the storage be freed, with the understanding that implementations might have a flag to allow optimizing away the overhead. Still others thought that both this issue and issue 219 should be resolved by forbidding a destructor to exit via an exception. No consensus was reached.

Date: 2004-09-10.00:00:00

Does the Standard require that the deallocation function will be called if the destructor throws an exception? For example,

    struct S {
        ~S() { throw 0; }
    };
    void f() {
        try {
            delete new S;
        }
        catch(...) { }
    }

The question is whether the memory for the S object will be freed or not. It doesn't appear that the Standard answers the question, although most people would probably assume that it will be freed.

History
Date User Action Args
2008-10-05 00:00:00adminsetmessages: + msg1836
2008-10-05 00:00:00adminsetstatus: open -> dup
2001-05-20 00:00:00adminsetmessages: + msg500
2000-11-21 00:00:00admincreate