What happens if delete[] p fails?

后端 未结 6 834
醉酒成梦
醉酒成梦 2021-02-07 03:52

Suppose I have a pointer to a dynamically allocated array of 10 elements:

T* p = new T[10];

Later, I want to release that array:



        
6条回答
  •  被撕碎了的回忆
    2021-02-07 04:35

    5.3.5.7 If the value of the operand of the delete-expression is not a null pointer value, the delete-expression will call a deallocation function (3.7.3.2). Otherwise, it is unspecified whether the deallocation function will be called. [ 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 ]

    Couldn't find anything about destructors except for

    In the case of an array, the elements will be destroyed in order of decreasing address (that is, in reverse order of the completion of their constructor; see 12.6.2).

    I guess that after throwing no more destructors are called, but I'm not sure.

提交回复
热议问题