I'm currently trying to understand in which cases g++ warns about uninitialized variables. Consider the following piece of code:
#include <iostream>
typedef double barType;
struct foo {
barType bar;
};
int main() {
foo f;
std::cout << f.bar << std::endl;
}
If I compile it like this I get no warning:
$ g++ -O1 -Wall test.cc -o test
but if I change barType to int:
$ g++ -O1 -Wall test.cc -o test
test.cc: In function ‘int main()’:
test.cc:17: warning: ‘f.foo::bar’ is used uninitialized in this function
How can the warning depend on the type? It is uninitialized in both cases.
I'm using:
$ g++ --version
g++ (Ubuntu 4.4.1-4ubuntu9) 4.4.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Thanks,
Somebody