From: Jamie Lokier <jamie@shareable.org>
To: gcc@gcc.gnu.org
Cc: Ross Dickson <ross@datscreative.com.au>, linux-kernel@vger.kernel.org
Subject: GCC feature request: warn on "if (function_name)"
Date: Sat, 14 Feb 2004 04:46:56 +0000 [thread overview]
Message-ID: <20040214044656.GI31199@mail.shareable.org> (raw)
In-Reply-To: <200402141124.50880.ross@datscreative.com.au>
Ross Dickson wrote:
> The fix is to put the brackets back on "!need_resched()" so that we call
> the function and test its return value - not just test the function pointer!
[ Ross' bug was writing "if (!need_resched)" instead of
"if (!need_resched())" ]
I'm very surprised GCC doesn't warn about that. A quick test confirms
GCC 3.2.2 at least doesn't.
So, this is a feature request:
- Warn when a function name is tested in a boolean context.
(A function pointer variable or expression should not be warned for).
By boolean context I mean any place where a function name is
used as a value and tested against zero. Some examples:
if (function_name)
if (function_name && ( <some other expression> ))
if (function_name != 0)
if (function_name == 0)
if (!function_name)
x = function_name ? a : b;
- Don't warn if there are two levels of parantheses.
I know it's occasionally useful to test the NULL-ness of a functin
name, of weak symbols. In most cases, though, it's a bug. If you
really want to check a weak symbol, just write "if ((symbol))". That
syntax is already well known for testing the result of an assignment,
as in "if ((x = 1))" does not yield a warning but "if (x = 1)" does.
Perhaps a later GCC than 3.2.2 already has this test; if someone is
able to check, that would be nice.
Thanks muchly :)
-- Jamie
next prev parent reply other threads:[~2004-02-14 4:47 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-11 15:22 [PATCH] 2.6, 2.4, Nforce2, Experimental idle halt workaround instead of apic ack delay Ross Dickson
2004-02-12 18:17 ` Derek Foreman
2004-02-12 16:11 ` Daniel Drake
2004-02-12 19:30 ` [PATCH] 2.6, 2.4, Nforce2, Experimental idle halt workaroundinstead " Carlos Silva
2004-02-12 19:54 ` [PATCH] 2.6, 2.4, Nforce2, Experimental idle halt workaround instead " Derek Foreman
2004-02-12 21:44 ` Jesse Allen
2004-02-12 21:52 ` Derek Foreman
2004-02-12 22:06 ` Craig Bradney
2004-02-12 23:04 ` Jesse Allen
2004-02-12 23:15 ` Craig Bradney
2004-02-12 23:37 ` Jesse Allen
2004-02-12 23:50 ` Craig Bradney
2004-02-12 23:20 ` Roberto Sanchez
2004-02-13 11:17 ` Prakash K. Cheemplavam
2004-02-13 14:41 ` Ross Dickson
2004-02-13 15:55 ` Nforce2, APIC, CPU Disconnect and setup_boot_APIC_clock() cheuche+lkml
2004-02-14 1:24 ` [PATCH] 2.6, 2.4, Nforce2, Experimental idle halt workaround instead of apic ack delay Ross Dickson
2004-02-14 4:46 ` Jamie Lokier [this message]
2004-02-14 4:51 ` GCC feature request: warn on "if (function_name)" Andrew Pinski
2004-02-14 11:16 ` [PATCH] 2.6, 2.4, Nforce2, Experimental idle halt workaround instead of apic ack delay Prakash K. Cheemplavam
2004-02-14 16:13 ` Ross Dickson
2004-02-14 21:46 ` Ian Kumlien
2004-02-23 1:33 ` Prakash K. Cheemplavam
2004-02-23 19:50 ` Jesse Allen
2004-02-23 1:37 ` Prakash K. Cheemplavam
2004-02-25 12:38 ` Ross Dickson
2004-02-25 19:49 ` Prakash K. Cheemplavam
2004-02-25 21:44 ` Arjen Verweij
2004-02-26 0:13 ` Ross Dickson
2004-02-26 9:59 ` Mikael Pettersson
2004-03-07 14:46 ` Craig Bradney
2004-03-08 22:42 ` Arjen Verweij
2004-03-08 22:59 ` Craig Bradney
2004-03-08 23:11 ` Arjen Verweij
2004-03-14 12:04 ` Arjen Verweij
2004-03-09 18:38 ` Josh McKinney
2004-03-24 15:59 ` Edd Dumbill
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040214044656.GI31199@mail.shareable.org \
--to=jamie@shareable.org \
--cc=gcc@gcc.gnu.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ross@datscreative.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox