Re: Missing warning about uninitialized variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Sveningsson <ext@xxxxxxxxxxx> writes:

> Hi, I recently ran into an issue with an uninitialized pointer which I
> expected g++ to warn about.
>
> class Foo {
> public:
>         Foo* a(){ return this; }
> };
>
> int main(int argc, const char*[] ){
>         for ( int i = 0; i < 6; i++ ){
>                 Foo* foo = foo->a();
>         }
> }
>
> This code compiles without any warnings (with -Wall) with both
> g++-4.4.2 and g++-4.2.4. Removing the for-loop gives me a warning as
> expected:
>
> foo.cpp: In function ‘int main(int, const char**)’:
> foo.cpp:8: warning: ‘foo’ is used uninitialized in this function
>
> I know this case is a bit silly but it happened because of a typo and
> went unnoticed for a while.
>
> Is my reasoning flawed or should g++ emit a warning?

You may get a warning with -Winit-self.

However, this sounds like a bug either way.  Please consider filing a
bug report as described at http://gcc.gnu.org/bugs/ .

Ian


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux