Bug 36866

Summary: lack of warning when initializing a class member from an uninitialized variable
Product: gcc Reporter: Imre Pentek <pentek.imre>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: fang, gcc-bugs, manu, myselfhimself, pawel_sikora, pentek.imre
Priority: P3    
Version: 4.1.2   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:
Attachments: any.cpp

Description Imre Pentek 2008-07-17 19:15:04 UTC
Hello, the attached code compiles without any warning when compiled with the command
g++ -W -Wall any.cpp -c -o any.o
but x gets initialised from itself, actually dereferencing x prior to initializing it. At this point it is trivial that x wasn't initialised.




Using built-in specs.
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.1.2/work/gcc-4.1.2/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.1.2 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.1.2 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.1.2/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.1.2/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --enable-nls --without-included-gettext --with-system-zlib --disable-checking --disable-werror --enable-secureplt --enable-multilib --enable-libmudflap --disable-libssp --enable-java-awt=gtk --enable-languages=c,c++,java,treelang,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
Thread model: posix
gcc version 4.1.2 (Gentoo 4.1.2 p1.1)
Comment 1 Imre Pentek 2008-07-17 19:16:12 UTC
Created attachment 15925 [details]
any.cpp
Comment 2 Manuel López-Ibáñez 2008-07-21 14:30:57 UTC
To fix this testcase we would need to fix a few of the -Wuninitialized issues, since -Wuninitialized does not work without optimisation, we don't handle VOPs (no -Wunitialized for pointers then), and -Winit-self is broken for some cases. Nonetheless, fixing PR19808 would be a start.

*** This bug has been marked as a duplicate of 19808 ***