c - gcc failing to warn of uninitialized variable -


the following code has variable may uninitialized. seems gcc should generating warning isn't:

$ cat a.c int foo(int b) {   int a;   if (b)     = 1;   return a; }  $ gcc-4.7 -c -wall -wmaybe-uninitialized -o a.o ./a.c $ gcc-4.7 -v using built-in specs. collect_gcc=gcc-4.7 collect_lto_wrapper=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper target: x86_64-linux-gnu configured with: ../src/configure -v --with-pkgversion='ubuntu/linaro 4.7.3-2ubuntu1~12.04' --with-bugurl=file:///usr/share/doc/gcc-4.7/readme.bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --with-system-zlib --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64 --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.7.3 (ubuntu/linaro 4.7.3-2ubuntu1~12.04) 

any clues on how gcc report uninitialized variable?

it looks can't - see this bug report. (and this one, marked dupe of 1 - has identical test case yours.) since looks root-cause bug 10 years old, seem it's not easy problem solve. in fact, second bug linked has phrase "never going fixed" in discussion, doesn't good.

if it's important you, clang does catch 1 -wsometimes-uninitialized, included -wall:

a.c:3:7: warning: variable 'a' used uninitialized whenever 'if' condition       false [-wsometimes-uninitialized]   if (b)       ^ a.c:5:10: note: uninitialized use occurs here   return a;          ^ a.c:3:3: note: remove 'if' if condition true   if (b)   ^~~~~~ a.c:2:8: note: initialize variable 'a' silence warning   int a;        ^         = 0 1 warning generated. 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -