Does std::make_shared value initalize members when there is a default ctor that fails to initailize its members?
I stumbled upon this when using a class where the default ctor did not initialize members using RAII style gave a warning and wondered why no warning was issued when it was used before elsewhere. Elsewhere it was using std::make_shared and I was thinking why it had been working before and no warning was issued.
#include <iostream>
#include <memory>
class Foo
{
public:
Foo() {} // should initalize mode but does not
int mode;
bool isZero() const
{
if (mode == 0) {
return true;
}
return false;
}
};
int main(int argc, const char* argv[])
{
auto blaa = std::make_shared<Foo>();
if (blaa->isZero()) { // No warning. Always zero initialized because using make_shared?
std::cout << "blaa.mode is zero\n";
}
Foo foo;
if (foo.isZero()) { // warning: 'foo' is used uninitialized in this function - as expected
std::cout << "foo.mode is zero\n";
}
return 0;
}