Initializing a dynamic array of non-default constructible objects

不羁岁月 提交于 2020-01-03 08:59:08

问题


The code below:

struct Foo
{
    Foo(int){} // no default constructor
};

int main()
{
    Foo* pFoo = new Foo[2]{1,2}; // OK in g++, fails in clang++!
    delete[] pFoo;
}   

compiles in gcc, but fails in clang. Is the code above syntactically correct?


回答1:


I'll turn @T.C. comment into an answer, so everyone sees what's going on without having to read through all of the comments.

This is a clang bug, the code should be accepted: http://llvm.org/bugs/show_bug.cgi?id=22924

Related: http://wg21.link/cwg2102



来源:https://stackoverflow.com/questions/37336319/initializing-a-dynamic-array-of-non-default-constructible-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!