public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Dubious "'foo' might be used uninitialized in this function" message
@ 2004-12-14 15:23 Dmitry Antipov
  2004-12-14 16:40 ` E. Weddington
  2004-12-14 17:00 ` Nathan Sidwell
  0 siblings, 2 replies; 13+ messages in thread
From: Dmitry Antipov @ 2004-12-14 15:23 UTC (permalink / raw)
  To: gcc

When compiling the following program,

#include <unistd.h>

int f (int x, int y)
{
  int z;

  if (x)
    z = getppid ();
  y = getpid ();
  if (x)
    y += z;
  return x + y + z;
}

GCC (with '-Wall') always says:

w.c: In function `f':
w.c:5: warning: 'z' might be used uninitialized in this function

which is not true.

Here 'z' is initialized under 'if (x)' condition, and 'z' always used under
'if (x)' condition. Also, it's clear that 'x' isn't accessed between 'if 
(x)',
so it's impossible to access uninitialized 'z'.

Is it reasonable to learn GCC do more analysis in attempt to avoid
warning in this case ? How is it complex ?

Also, IMHO it would be better to point to the place where
uninitialized variable may be _used_ and not to the place where
it's _declared_ ('y += z' in this case). Or even to both places.

For example, for the following program:

#include <unistd.h>

int f (int x, int y)
{
  int z;

  if (x)
    z = getppid ();
  y = getpid ();
  y += z;
  return x + y + z;
}

it would be better to get:

w.c: In function `f':
w.c:10: warning: uninitialized 'z' might be used
w.c:5: warning: ('z' declared here)

Thanks,
Dmitry

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2004-12-15 18:09 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-14 15:23 Dubious "'foo' might be used uninitialized in this function" message Dmitry Antipov
2004-12-14 16:40 ` E. Weddington
2004-12-14 17:00 ` Nathan Sidwell
2004-12-15  9:00   ` Dmitry Antipov
2004-12-15 10:02     ` Nathan Sidwell
2004-12-15 12:06     ` Robert Dewar
2004-12-15 17:33       ` Joe Buck
2004-12-15 18:03         ` Dave Korn
2004-12-15 18:09           ` Robert Dewar
2004-12-15 17:33       ` Florian Weimer
2004-12-15 17:34         ` Robert Dewar
2004-12-15 17:52           ` Florian Weimer
2004-12-15 18:00             ` Robert Dewar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).