[Bug c/58236] New: -Wuninitialized doesn't report uninitialised variable as expected
noufal at nibrahim dot net.in
gcc-bugzilla@gcc.gnu.org
Sat Aug 24 06:38:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58236
Bug ID: 58236
Summary: -Wuninitialized doesn't report uninitialised variable
as expected
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: noufal at nibrahim dot net.in
Created attachment 30695
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30695&action=edit
Test case program
Command run
-----------
gcc was run like so
gcc -Wall program.c
I also tried running
gcc -Wuninitialized program.c
The program is attached to this bug report.
Behaviour
---------
#include <stdio.h>
void test()
{
int iters;
while(iters++ <= 100) {
printf("%d\n", iters);
}
}
int main()
{
test();
return 0;
}
In the program above, the 'iters' variable is not initialised. This makes the
loop sometimes behave in unexpected ways. Ideally, the -Wuninitialized option
should warn about this. This doesn't happen.
With clang, I get the following output
noufal@sanitarium% clang -Wall program.c
program.c:7:9: warning: variable 'iters' is uninitialized when used here
[-Wuninitialized]
while(iters++ <= 100) {
^~~~~
program.c:5:12: note: initialize the variable 'iters' to silence this warning
int iters;
^
= 0
1 warning generated.
I tested this with the stock Debian gcc (4.6.3) but friends have tried it on
4.6, 4.7 and 4.8 and reported the same problem.
gcc -v output
--------------
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.3-1'
--with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin
--enable-objc-gc --with-arch-32=i586 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Debian 4.6.3-1)
System type
-----------
uname -a output:
Linux sanitarium 3.1.0-1-amd64 #1 SMP Sun Dec 11 20:36:41 UTC 2011 x86_64
GNU/Linux
This is running on an Lenovo Thinkpad X201.
More information about the Gcc-bugs
mailing list