初始化非缺省构造对象的动态数组 [英] Initializing a dynamic array of non-default constructible objects

查看:187
本文介绍了初始化非缺省构造对象的动态数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下code:

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

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

编译gcc的,但是的失败的铛。是code以上语法正确的?

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

推荐答案

我要把@ T.C。到答案发表评论,所以每个人都看到发生了什么事情,而不必通过所有的评论的阅读。

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.

这是一个错误铿锵的code应该被接受:的http:/ /llvm.org/bugs/show_bug.cgi?id=22924

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

相关报道: http://wg21.link/cwg2102

这篇关于初始化非缺省构造对象的动态数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆