This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Error in -Wuninitialized? Should this be reported?


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]