c++ - 为什么逗号表达式用作放置参数时不能按预期工作?

标签 c++ visual-c++ compiler-errors expression standards

#include <new>

using namespace std;

void f(void*)
{}

struct A
{};

int main()
{
    A a;

    f((a.~A(), &a)); // OK
    new (&a) A();    // OK

    new ((a.~A(), &a)) A(); // error C2059: syntax error : 'type'
}

我认为 (a.~A(), &a) 是一个有效的表达式,可以计算为一个指针值,所以它应该被接受为放置参数,为什么结果不是这样?

我的编译器是 VC++ 2013 RC。这是编译器错误吗?

更新:

我已经向 connect.microsoft.com 提交了一个错误

最佳答案

是的,这是一个编译器错误,语法是正确的。

可以看看标准中的语法:

new-placement:
( expression-list )

并且,a.~A(), &a 作为表达式列表是有效的。

关于c++ - 为什么逗号表达式用作放置参数时不能按预期工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19042093/

相关文章:

c++ - 'operator new' : redefinition, 不同的链接(在重新定义的新运算符上使用 _dllspec)

c++ - 如何在 C++ 跨平台中获取用户的组列表?

windows - cpprestsdk SSL post 不适用于 Windows7 但适用于 Windows 10

c++ - 不断收到错误: expected unqualified id at end of input- C++

angular - 编译 Angular 项目时出错

c++ - 是否有能力倒回 VideoCapture 中的多个帧

c++ - 如何使用 boost::spirit 验证代数语句?

visual-c++ - VC++ 增量链接器错误 LNK1000

c++ - 如何创建一个随机的 bit64 值

php - PHP无法解析类中的串联字符串