public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: "Joseph S. Myers" <joseph@codesourcery.com>,
	       Jason Merrill <jason@redhat.com>,
	gcc-patches@gcc.gnu.org
Subject: Re: [C/C++ PATCH] -Wlogical-not-parentheses tweaks (PR c/65120)
Date: Fri, 20 Feb 2015 15:47:00 -0000	[thread overview]
Message-ID: <20150220153505.GE23138@redhat.com> (raw)
In-Reply-To: <20150220000326.GT1746@tucnak.redhat.com>

On Fri, Feb 20, 2015 at 01:03:26AM +0100, Jakub Jelinek wrote:
> Hi!
> 
> As reported, !!x == y is quite common in the Linux kernel
> and unlike the !x == y case it usually doesn't mean mistyped
> !(x == y) or x != y.  clang++ apparently doesn't warn about that
> either, and it doesn't warn even about the case where ! is applied
> to a bool.

Note that first version of -Wlogical-not-parentheses didn't warn
when LHS had a boolean type, this has been changed later on.  I have
no strong preference either way.

> As the argument is already folded, it isn't easy to determine
> those cases always, but I hope the following is sufficient until we switch
> to late folding.
 
Yes, this means that we warn for

  return !(a != 0) == b;

but not for

  return !(a == 0) == b;

I think we can live with that for now.

> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2015-02-19  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c/65120
> 	* c-typeck.c (parser_build_binary_op): Don't warn for
> 	!!x == y or !b == y where b is _Bool.
> 
> 	* parser.c (cp_parser_binary_expression): Don't warn for
> 	!!x == y or !b == y where b is bool.
> 
> 	* c-c++-common/pr49706.c: Adjust tests for not warning
> 	about !!x == y or !b == y where b is boolean, and add
> 	some further tests.
> 	* c-c++-common/pr62199-2.c: Likewise.

The C part is ok.  Maybe we should also update the docs to reflect that
-Wlogical-not-parentheses does not warn if the RHS *or LHS* operand is of
a boolean type.  Thanks,

	Marek

  reply	other threads:[~2015-02-20 15:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-20  0:09 Jakub Jelinek
2015-02-20 15:47 ` Marek Polacek [this message]
2015-02-20 16:12   ` Jakub Jelinek
2015-02-27 23:23 ` Jason Merrill
2015-03-09 14:35   ` Jakub Jelinek
2015-03-09 16:13     ` Jason Merrill
2015-04-10 19:40 ` Gerald Pfeifer

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=20150220153505.GE23138@redhat.com \
    --to=polacek@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jason@redhat.com \
    --cc=joseph@codesourcery.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).