This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

-Wuninitialized not so hot.



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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]