public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Sebor <msebor@gmail.com>
To: Mark Wielaard <mjw@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Warn when comparing nonnull arguments to NULL in a function.
Date: Tue, 15 Sep 2015 03:43:00 -0000	[thread overview]
Message-ID: <55F79274.5080602@gmail.com> (raw)
In-Reply-To: <1441835087-14555-1-git-send-email-mjw@redhat.com>

> +void foo(void *bar) __attribute__((nonnull(1)));
> +
> +void foo(void *bar) { if (!bar) abort(); } /* { dg-warning "null" "argument ‘bar’ compared to NULL" } */

This looks like a very useful enhancement. Since the change is limited
to build_binary_op in the two front ends I wonder if the warning also
issued for other expressions? For example, suppose I were to add to
function foo above the following:

      bool is_null = bar;

would GCC issue a warning? The same question goes for other expressions
non-binary expressions, including:

      bar ? f () : g ();

or in C++:

      bool x = static_cast<bool>(bar);

If not, I would think issuing it would make the feature even more
useful (and the diagnostics more consistent).

Martin

  parent reply	other threads:[~2015-09-15  3:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-09 21:51 Mark Wielaard
2015-09-09 22:02 ` Jeff Law
2015-09-09 22:33   ` Jakub Jelinek
2015-09-09 23:01     ` Mark Wielaard
2015-09-14 19:26       ` Jeff Law
2015-09-15  3:43 ` Martin Sebor [this message]
2015-09-15  8:48   ` Mark Wielaard
2015-09-15 12:22     ` Manuel López-Ibáñez
2015-09-15 16:27       ` Mark Wielaard
2015-09-15 14:56     ` Martin Sebor

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=55F79274.5080602@gmail.com \
    --to=msebor@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mjw@redhat.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).