【发布时间】:2015-04-23 19:16:52
【问题描述】:
以下代码在 GCC 和 Clang 上给出了不同的结果。谁是对的?
union Foo {
struct {
int a;
int b;
};
};
struct Bar {
Bar(void) : test{.a = 1, .b = 2} { }
Foo test;
};
使用 GCC 时出现以下错误(使用 Clang 可以正常编译):
arcanis@/tmp # g++ -std=c++11 x.cpp
x.cpp: In constructor ‘Bar::Bar()’:
x.cpp:9:36: error: too many initializers for ‘Foo’
Bar(void) : test{.a = 1, .b = 2} { }
^
【问题讨论】:
标签: c++11 gcc clang initializer-list