From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15441 invoked by alias); 31 Jan 2003 05:28:40 -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 15433 invoked from network); 31 Jan 2003 05:28:39 -0000 Received: from unknown (HELO mulga.cs.mu.OZ.AU) (128.250.1.22) by 172.16.49.205 with SMTP; 31 Jan 2003 05:28:39 -0000 Received: from ceres.cs.mu.oz.au (mail@ceres.cs.mu.OZ.AU [128.250.33.10]) by mulga.cs.mu.OZ.AU with ESMTP id QAA08821; Fri, 31 Jan 2003 16:28:25 +1100 (EST) Received: from fjh by ceres.cs.mu.oz.au with local (Exim 3.35 #1 (Debian)) id 18eTiz-0004Up-00; Fri, 31 Jan 2003 16:28:25 +1100 Date: Fri, 31 Jan 2003 10:48:00 -0000 From: Fergus Henderson To: Alexandre Oliva Cc: Jan Hubicka , Andrew Morton , gcc@gcc.gnu.org Subject: Re: possible bug Message-ID: <20030131052825.GB15725@ceres.cs.mu.oz.au> References: <3E39BF1D.A0D038EF@digeo.com> <20030131001301.GJ15049@kam.mff.cuni.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.28i X-SW-Source: 2003-01/txt/msg01738.txt.bz2 On 31-Jan-2003, Alexandre Oliva wrote: > On Jan 30, 2003, Jan Hubicka wrote: > > >> char *zot(void) > >> { > >> return ({foo(); 0; }); > >> } > >> mnm:/home/akpm> /usr/local/gcc-3.2.1/bin/gcc -O -Wall -c t.c > >> t.c: In function `zot': > >> t.c:10: warning: return makes pointer from integer without a cast > > >> I think the warning is bogus? No, the warning is valid. The function body calls foo(), evaluations the expression `0' with type `int', and then converts the `int' to `char *' without a cast. > > I think the value of ({foo(); 0; }) is zero (value of last statement, > > if I recall the definition), so it is corect. > > But then, zero is a NULL pointer constant, isn't it? At least in C++, > a warning would have been very inappropriate. I don't think one for C > is. `0' is a null pointer constant. But `{foo(); 0;}' is not. And it is the latter which is being converted to a pointer. The code shown here is exactly analagous to char *zot(void) { return (foo(), 0); } except that it uses a GNU C statement-expression instead of a comma-expression. In both cases, the `0' expression does not itself occur in a context in which that `0' expression itself is being converted to a pointer; instead, the `0' expresion itself has type `int', and the more complicated expression containing it, which is not a null pointer constant, is the one that is being converted to a pointer. Since the more complicated expression is not itself a null pointer constant, a diagnostic is required. -- Fergus Henderson | "I have always known that the pursuit The University of Melbourne | of excellence is a lethal habit" WWW: | -- the last words of T. S. Garp.