以下代码可以使用 GCC 正常编译:
constexpr struct {} s;
但 Clang 拒绝了它,并出现以下错误:
错误:默认初始化 const 类型“const struct (anonymous struct at ...)”对象,而没有用户提供的默认构造函数
我已经测试了我能找到的所有版本的 GCC 和 Clanghttps://gcc.godbolt.org/ https://gcc.godbolt.org/。每个版本的 GCC 都接受该代码,每个版本的 Clang 都拒绝它。
我想知道在这种情况下哪个编译器是正确的?
标准对此有何规定?
Clang 遵循以下段落:[dcl.init]/7 http://eel.is/c++draft/dcl.init#7:
如果程序调用 const 限定类型的对象的默认初始化T
, T
应是具有用户提供的默认构造函数的类类型。
This wording is defective https://cplusplus.github.io/CWG/issues/253.html and hence ignored by GCC https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57820#c5 (and, as of v3.9, also by Clang http://melpon.org/wandbox/permlink/Ed7vbGe0UTO1c9sz).
The above quote differs from core issue 253's due to N2762 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2762.htm moving/adjusting paragraph 9 as cited.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)