mercredi 15 avril 2015

Initializer list constructor for struct with default values


struct S {
int a = 1;
int b = 2;
};


The following both compile with clang 3.5 and do not compile with gcc 4.9.2



S s = {10};
S s2 = {10, 20};


The error from gcc lists the only candidate constructors as the default constructor, the copy constructor, and the move constructor. This implies that adding a default value to a class means it can't be brace initialized (without user-defined constructors), but since clang compiles this without errors or unexpected behavior (s.b == 2), who is right?


Aucun commentaire:

Enregistrer un commentaire