Why is an overloaded delete not called when an exception is thrown in a destructor?

后端 未结 3 1865
温柔的废话
温柔的废话 2021-01-12 02:39

I\'ve written the below code which overloads the new and delete operators and throws an exception in the destructor.

When the exception is

3条回答
  •  孤独总比滥情好
    2021-01-12 03:32

    The standard Draft N4296 5.3.5, pag 121 says:

    [expr.delete] [ Note: The deallocation function is called regardless of whether the destructor for the object or some element of the array throws an exception. — end note ]

    So the operator delete has to be called regardeless the destructor throws.

    However, as has emerged from the comments, some compilers does not properly call the operator delete. This can be resolved as bug compiler.

    Bug tested for:

    • GCC 4.8
    • Visual Studio 2015

提交回复
热议问题