This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Error in -Wuninitialized? Should this be reported?
- From: "Richard Guenther" <richard dot guenther at gmail dot com>
- To: "Goswin von Brederlow" <goswin-v-b at web dot de>
- Cc: GCC <gcc at gcc dot gnu dot org>
- Date: Sun, 7 Dec 2008 13:20:45 +0100
- Subject: Re: Error in -Wuninitialized? Should this be reported?
- References: <87vdtwacw6.fsf@frosties.localdomain>
On Sun, Dec 7, 2008 at 4:21 AM, Goswin von Brederlow <goswin-v-b@web.de> wrote:
> 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?
Well, the compiler just sees
Bar::Bar() (struct Bar * const this)
{
int * D.1736;
<bb 2>:
D.1736_2 = this_1(D)->p;
*D.1736_2 ={v} 1;
return;
}
where 'this' is a incoming pointer. It obviously doesn't know that it
is supposed to
be initialized in this function. That is, -Wuninitialized doesn't know about
constructors.
Richard.