To use an uninitialized object of built-in type with automatic storage duration is undefined behaviour. Of course I recommend strongly always to initialize member variables of built-in type inside a class type. Despite that, I assume that a member of built-in type without an initializer is always initialized to zero, if the corresponding object of class type has static storage duration (i.e. global object). My assumption is, that the complete memory of an object of class type with static storage duration is zeroed out.
Example:
#include <iostream>
using namespace std;
class Foo {
public:
int bar;
};
Foo a;
int main() {
Foo b;
cout << "a.bar " << a.bar << "\n";
cout << "b.bar " << b.bar << "\n";
return 0;
}
Compile:
$ g++ -o init init.cpp -Wall -pedantic # gcc 7.2.1
init.cpp: In function ‘int main()’:
init.cpp:14:31: warning: ‘b.Foo::bar’ may be used uninitialized in this function [-Wmaybe-uninitialized]
cout << "b.bar " << b.bar << "\n";
^~~~
GCC complains only about the member, of class type object with automatic-storage duration b.bar not a.bar. So I am right?
Please feel free to modify the title of this question.
Thank you