c++ - Placement-new 是否引入了序列点?

标签 c++ exception constructor side-effects sequence-points

考虑以下代码行:

new (p++) T();

如果构造函数T()抛出异常,是否保证p已经自增?

最佳答案

来自 5.3.4 [expr.new](引自 n3242):

11 The new-placement syntax is used to supply additional arguments to an allocation function. If used, overload resolution is performed on a function call created by assembling an argument list consisting of the amount of space requested (the first argument) and the expressions in the new-placement part of the new-expression (the second and succeeding arguments).

所以在一个新的表达式中,分配函数是从函数调用中使用的(这是有道理的)。所有分配函数都是函数,包括实现提供的函数,来自 3.7.4.1 [basic.stc.dynamic.allocation]:

1 An allocation function shall be a class member function or a global function; [...]

所以当构造函数抛出异常时,分配已经发生并且相关的函数调用表达式已经被完全评估。

关于c++ - Placement-new 是否引入了序列点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6496912/

相关文章:

java - selenium webdriver - 构造 Action 点击和发送键

c++ - 对惰性计算决胜元素的 vector 进行排序

c++ - 比较 (int)double 和 (int)int 时出现异常

c++ - 什么终止将输入读入 int

vb.net - Task.Run - 处理异常

c# - .NET try/catch 便宜吗?

派生类的C++初始化列表编译失败,为什么?

c++ - 关于C++中构造函数链的一些问题

c++ - 刷新文件读取缓存

c++ - 与 glfw3 链接时出错