GCC 接受 `constexpr struct {} s;` 但 Clang 拒绝它。谁是正确的?
GCC accepts `constexpr struct {} s;` but Clang rejects it. Who is correct?
下面的代码可以用 GCC 编译:
constexpr struct {} s;
但 Clang 拒绝它并出现以下错误:
error: default initialization of an object of const type 'const struct (anonymous struct at …)' without a user-provided default constructor
我已经测试了我能够在 https://gcc.godbolt.org/ 找到的所有版本的 GCC 和 Clang。每个版本的 GCC 都接受代码,每个版本的 Clang 都拒绝它。
我想知道在这种情况下哪个编译器是正确的?
标准对此有何规定?
Clang 遵循 [dcl.init]/7 中的以下段落:
If a program calls for the default initialization of an object of a const-qualified type T
, T
shall be a class type with a user-provided default constructor.
这个写法是defective and hence ignored by GCC (and, as of v3.9, also by Clang)。
由于引用了 N2762 moving/adjusting 第 9 段,上述引述与核心问题 253 不同。
下面的代码可以用 GCC 编译:
constexpr struct {} s;
但 Clang 拒绝它并出现以下错误:
error: default initialization of an object of const type 'const struct (anonymous struct at …)' without a user-provided default constructor
我已经测试了我能够在 https://gcc.godbolt.org/ 找到的所有版本的 GCC 和 Clang。每个版本的 GCC 都接受代码,每个版本的 Clang 都拒绝它。
我想知道在这种情况下哪个编译器是正确的?
标准对此有何规定?
Clang 遵循 [dcl.init]/7 中的以下段落:
If a program calls for the default initialization of an object of a const-qualified type
T
,T
shall be a class type with a user-provided default constructor.
这个写法是defective and hence ignored by GCC (and, as of v3.9, also by Clang)。
由于引用了 N2762 moving/adjusting 第 9 段,上述引述与核心问题 253 不同。