[Bug c++/19808] miss a warning about uninitialized member usage in member initializer list in constructor

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue May 8 11:33:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19808

--- Comment #37 from Jonathan Wakely <redi at gcc dot gnu.org> ---
N.B. we should also warn using uninitialized members in default member
initializers, e.g. both of these should produce a warning:

struct X {
  int x1 = x2;
  int x2 = 0;
};

X x{};  // causes definition of default constructor

struct Y {
  int y1 = y2;
  int y2;
  Y() : y2(0) { }
};

Clang warns about both:

defmeminit.cc:2:12: warning: field 'x2' is uninitialized when used here
[-Wuninitialized]
  int x1 = x2;
           ^
defmeminit.cc:6:3: note: in implicit default constructor for 'X' first required
here
X x{};
  ^
defmeminit.cc:1:8: note: during field initialization in the implicit default
constructor
struct X {
       ^
defmeminit.cc:9:12: warning: field 'y2' is uninitialized when used here
[-Wuninitialized]
  int y1 = y2;
           ^
defmeminit.cc:11:3: note: during field initialization in this constructor
  Y() : y2(0) { }
  ^
2 warnings generated.


More information about the Gcc-bugs mailing list