On 09/14/2016 05:34 AM, Bernd Schmidt wrote:
On 09/14/2016 02:45 AM, David Malcolm wrote:
In combination with -fdiagnostics-generate-patch this can generate output
like this:

  --- ../../src/gcc/testsuite/c-c++-common/fix-missing-initializer-1.c
  +++ ../../src/gcc/testsuite/c-c++-common/fix-missing-initializer-1.c
  @@ -2,7 +2,7 @@

   int test_int (void)
   {
  -  int ivar;
  +  int ivar = 0;
     return ivar;  /* { dg-warning "used uninitialized" } */
     /* { dg-begin-multiline-output "" }
      return ivar;

I have to admit I feel uneasy about this. Just initializing stuff to
zero is the naive approach to shutting up the warning, but there's no
reason to think it's the correct fix. I think this is a warning where a
human who understands what's supposed to be going on needs to take a
look. Automating the work of a bad programmer seems like it could lead
to rather unfortuante outcomes.
I'd started writing something longer which said the same essentially the same thing.

For uninitialized variable uses the thing to do is to provide a human readable explanation of the path (conditions) which lead to the uninitialized use. The developer really needs to decide what to do to fix their code.

jeff

Reply via email to