http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57758
Bug ID: 57758 Summary: gcc accepts incorrect in-class brace initializers Product: gcc Version: 4.8.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: lundberj at gmail dot com In summary, having a class member in-class copy-construct from itself (!) compiles without warning when curly-brace syntax is used. The result is that the class invariants are never established. The following code is accepted: #include <iostream> struct C{ C()=delete; C(const C& other): x(other.x+1){} int x=10; }; struct D{ C c0{c0}; // << -- compiles without warning //C c1{c1}; // << -- correctly rejected }; int main(){ D d; std::cout << d.c0.x << std::endl; // prints 1 } You already get the point. Similarly, these definitions of C also compiles, and the printed value of x is 0 in both cases. struct C{ int x=10; C(float,float){} }; struct C{ int x=10; }; Using the following definition I get an un-initialized reference: x == 1412476 : struct C{ C(const C& other): z(other.z),x(other.x){} int z=10; int & x{z}; }; This seems like something that would be good to detect. Using class C{}; is correctly rejected (with 'too many initializers for āCā').