1

I understand that c++ variable initialization is extremely complicated and not all compilers 100% conform to the standard, if it's well defined in the first place. Therefore, I want to generate warnings in our whole codebase wherever a variable is not explicitly initialized.

Through my search, I came across these two flags: -Wmissing-field-initializers and -Wconditional-uninitialized, which look promising. So, I tried the following test code:

#include <iostream>

class Foo {
private:
  int bar;

public:
  Foo() {}
  int Bar() { return bar; }
};

int main () {
  Foo foo;
  std::cout << foo.Bar();
  return 0;
}

where Foo::bar is not initialized anywhere: it's not value initialized, the constructor is user defined and does not initialize bar. However, when I compiled it with clang++ -std=c++17 -Wmissing-field-initializers -Wmissing-field-initializers, I'm not getting any warnings.

What am I missing here? Thanks.

Deling Ren
  • 87
  • 4

0 Answers0