This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Error in -Wuninitialized? Should this be reported?
- From: Goswin von Brederlow <goswin-v-b at web dot de>
- To: GCC <gcc at gcc dot gnu dot org>
- Date: Sun, 07 Dec 2008 04:21:29 +0100
- Subject: Error in -Wuninitialized? Should this be reported?
Hi,
After spending the better part of the evening finding a bug caused by
an uninitialized pointer I would love to get a Warning about
uninitialized variables from g++ in cases like Foo, Bar and Baz below:
mrvn@frosties:~% cat foo.cc
class Foo {
Foo() { }
int *p;
};
class Bar {
Bar() { *p = 1; }
int *p;
};
class Baz {
Baz() { }
int get_p() { return *p; }
int *p;
};
mrvn@frosties:~% g++ -g -O2 -W -Wall -Werror -Wuninitialized -c foo.cc
mrvn@frosties:~% g++ --version
g++ (Debian 4.3.2-1) 4.3.2
Copyright (C) 2008 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.
In Foo the variable is just uninitialized, in Bar it is definetly used
uninitialized and in Baz it might be used uninitialized. Is there any
-W switch to make g++ detect such errors or is that a shortcomming of
-Wuninitialized?
MfG
Goswin