Created on 2002-04-30.00:00:00 last changed 197 months ago
[Voted into WP at April 2003 meeting.]
[Voted into WP at April 2003 meeting.]
In a couple of comp.std.c++ threads, people have asked whether the Standard guarantees that the deallocation function will be called in a delete-expression if the destructor throws an exception. Most/all people have expressed the opinion that the deallocation function must be called in this case, although no one has been able to cite wording in the Standard supporting that view.
#include <new.h> #include <stdio.h> #include <stdlib.h> static int flag = 0; inline void operator delete(void* p) throw() { if (flag) printf("in deallocation function\n"); free(p); } struct S { ~S() { throw 0; } }; void f() { try { delete new S; } catch(...) { } } int main() { flag=1; f(); flag=0; return 0; }
Proposed resolution (October 2002):
Add to 7.6.2.9 [expr.delete] paragraph 7 the highlighted text:
The delete-expression will call a deallocation function (6.7.6.5.3 [basic.stc.dynamic.deallocation]) [Note: The deallocation function is called regardless of whether the destructor for the object or some element of the array throws an exception. ]
History | |||
---|---|---|---|
Date | User | Action | Args |
2008-10-05 00:00:00 | admin | set | status: wp -> cd1 |
2003-04-25 00:00:00 | admin | set | messages: + msg860 |
2003-04-25 00:00:00 | admin | set | status: ready -> wp |
2002-11-08 00:00:00 | admin | set | messages: + msg729 |
2002-11-08 00:00:00 | admin | set | status: open -> ready |
2002-04-30 00:00:00 | admin | create |