if nothrow new return nullptr 是否调用构造函数?
Is constructor called if nothrow new return nullptr?
如果我使用 new
并得到 std::bad_alloc
编译器因为异常不会调用构造函数。但是它如何与 nothrow new
一起工作,因为我们在每种情况下都会得到指针?这种情况在标准中有专门的段落吗?
[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.
如果我使用 new
并得到 std::bad_alloc
编译器因为异常不会调用构造函数。但是它如何与 nothrow new
一起工作,因为我们在每种情况下都会得到指针?这种情况在标准中有专门的段落吗?
[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.