From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15549 invoked by alias); 14 Dec 2004 15:23:54 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 15469 invoked from network); 14 Dec 2004 15:23:43 -0000 Received: from unknown (HELO mail.dev.rtsoft.ru) (80.240.96.70) by sourceware.org with SMTP; 14 Dec 2004 15:23:43 -0000 Received: (qmail 29471 invoked from network); 14 Dec 2004 14:56:09 -0000 Received: from unknown (HELO ?192.168.1.213?) (192.168.1.213) by mail.dev.rtsoft.ru with SMTP; 14 Dec 2004 14:56:09 -0000 Message-ID: <41BF1207.2040102@dev.rtsoft.ru> Date: Tue, 14 Dec 2004 15:23:00 -0000 From: Dmitry Antipov User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20040913 MIME-Version: 1.0 To: gcc@gcc.gnu.org Subject: Dubious "'foo' might be used uninitialized in this function" message Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2004-12/txt/msg00510.txt.bz2 When compiling the following program, #include 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 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