From the comment of this answer :
Class members are initialized in the order they are declared. By this logic, the following constructor should refer to undefined behavior:
struct Foo { Bar a; Bar b; Foo(Bar c) : a(b = c) { } };
Apparently, we assign b before a is initialized. Assignment to an uninitialized object must be UB. Not surprisingly, the code “works” with Bar = int , but if I make Bar heavy class with constructors, I see that b really initialized to a .
(For superfluous madness, we can even say Foo(Bar c, Bar d) : a(b = c), b(d) { } , still without warning.)
However, GCC 4.6.1 does not warn about this. Is this acceptable, well-defined behavior, or is it strictly wrong?
source share