dimanche 22 février 2015

Is this code valid or not? GCC and Clang disagree

The following code gives me different results on GCC and Clang. Who's right?



union Foo {
struct {
int a;
int b;
};
};

struct Bar {
Bar(void) : test{.a = 1, .b = 2} { }
Foo test;
};


I get the following error with GCC (and it compiles fine with 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} { }
^

Aucun commentaire:

Enregistrer un commentaire