Search code examples
c++pointersexceptionnew-operatornothrow

Is constructor called if nothrow new return nullptr?


If I use new and get std::bad_alloc compiler do not call constructor because of exception. But how does it works with the nothrow new cause we get pointer in every case? Is there special paragraph in standard for this case?


Solution

  • [expr.new]/16 ... if the allocation function returns null, initialization shall not be done, the deallocation function shall not be called, and the value of the new-expression shall be null.