As mentioned in this answer, just calling the destructor a second time already has undefined behavior 12.4 / 14 (3.8).
For example:
class Class { public: ~Class() {} };
In this example, the class is designed so that the destructor can be called several times - things like double deletion cannot happen. The memory is still allocated at the point where delete is called - the first call to the destructor does not call ::operator delete() to free the memory.
For example, in Visual C ++ 9, the above code looks workable. Even C ++ - defining UB does not directly prohibit working like UB. Thus, for the above code, it is necessary to fulfill some implementation and / or platform requirements.
Why is this code broken and under what conditions?
c ++ memory-management undefined-behavior memory destructor
sharptooth May 05 '10 at 8:26 a.m. 2010-05-05 08:26
source share