From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4116 invoked by alias); 14 Dec 2004 16:40:06 -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 4038 invoked from network); 14 Dec 2004 16:39:58 -0000 Received: from unknown (HELO www.evcohs.com) (66.17.141.91) by sourceware.org with SMTP; 14 Dec 2004 16:39:58 -0000 Received: (qmail 2100 invoked from network); 14 Dec 2004 16:39:58 -0000 Received: from unknown (HELO [10.0.1.12]) (66.180.104.54) by 66.17.141.91 with SMTP; Tue, 14 Dec 2004 16:39:58 +0000 Message-ID: <41BF17A8.3080906@evcohs.com> Date: Tue, 14 Dec 2004 16:40:00 -0000 From: "E. Weddington" User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) MIME-Version: 1.0 To: Dmitry Antipov CC: gcc@gcc.gnu.org Subject: Re: Dubious "'foo' might be used uninitialized in this function" message References: <41BF1207.2040102@dev.rtsoft.ru> In-Reply-To: <41BF1207.2040102@dev.rtsoft.ru> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2004-12/txt/msg00513.txt.bz2 Dmitry Antipov wrote: > 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 ? > Even if you rearranged the code to remove your warning above: int f (int x, int y) { int z; y = getpid (); if (x) { z = getppid (); y += z; } return x + y + z; } You'll still get an uninitialized variable warning for your return statement, where you do use z uninitialized.