【发布时间】:2015-04-07 08:43:23
【问题描述】:
我有代码:
struct A {
int a;
};
struct B {
int b;
const A a[2];
};
struct C {
int c;
const B b[2];
};
const C test = {0, {}};
int main()
{
return test.c;
}
我有 gcc 4.8.2 和 4.9.2。它可以编译得很好:
g++-4.9 -Wall test.cpp -o test
g++-4.8 -std=c++11 -Wall test.cpp -o test
g++-4.8 -Wall test.cpp -o test
但是,它不能编译:
g++-4.9 -std=c++11 -Wall test.cpp -o test
而编译器的输出是:
test.cpp:15:22: error: uninitialized const member ‘B::a’
const C test = {0, {}};
^
test.cpp:15:22: error: uninitialized const member ‘B::a’
这是一个错误还是我只是不明白什么?
【问题讨论】:
-
你试过 Cland 或 GCC 5 吗?
-
@usr1234567 在 clang 3.5 中编译时没有警告
-
还有compiles on GCC trunk。看起来已经修复了一个错误。
-
@T.C.请将其添加为答案,如果您不想代表,则将其设为 CW。正如我们在许多元问题中看到的那样,cmets 并不意味着会留下来,而且我之前已经看到重要的 cmets 被删除了。如此重要的细节不属于 cmets。