-Wuninitialized not so hot.

Trent Waddington trentw@vmware.com
Wed Jun 13 18:55:00 GMT 2001


The warning option -Wuninitialized does not result in a warning message if
the address of a possibily uninitialized variable is taken, even if
after the first use.  This actually occured and was a source of
frustration.  For example the following program:

#include <stdio.h>

int checkit(int i) {
   return i % 16;
}

void modit(int *i) {
   *i = 5;
}

int main(int argc, char * argv[])
{
   int noinithere;

   if (checkit(noinithere)) {
      printf("terribly bad situation\n");
      return 1;
   }

   modit(&noinithere);

   return 0;
}

Compiling this program using options -Wuninitialized -O results in no
warnings.  However, commenting out the call to modit gives the correct
warning.  In other news, I'm informed a complete lack of warning for this
program:

int main(int argc, char * argv[])
{
   int foo = foo;
}

also wasted a few hours of debugging.

Trent Waddington
VMWare Code Monkey.



More information about the Gcc-bugs mailing list