问题
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