If I have a class:
class MyClass { public: int value; }; It's member value won't be zero-initialized if I don't zero-initialize the class:
MyClass c; std::cout << c.value; // UB: value not initialized. Does defaulting the default constructor guarantee that members are zero-initialized?
class MyClass { public: int value; MyClass() = default; }; If I explicitly default the default constructor, will value be initialized to zero now?
MyClass c; std::cout << c.value; // Guaranteed to print zero? Note: This question is not a duplicate because I'm asking about the case where the default constructor is explicitly defaulted, and the other question just covers the case where it's not provided.
'c.MyClass::value' is used uninitialized in this function [-Wuninitialized]and print 0, but Clang won't issue you a warning, and will print 0. I'm talking about the latest Clang 9.0.1 and Gcc 9.0.1