From: Bernd Edlinger <bernd.edlinger@hotmail.de>
To: Joseph Myers <joseph@codesourcery.com>,
Marek Polacek <polacek@redhat.com>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: C/C++ PATCH for c/77423 (bogus warning with -Wlogical-not-parentheses)
Date: Mon, 05 Sep 2016 17:03:00 -0000 [thread overview]
Message-ID: <AM4PR0701MB21625230823BC1CBBBCEF4B9E4E60@AM4PR0701MB2162.eurprd07.prod.outlook.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1609051642420.16161@digraph.polyomino.org.uk>
On 09/05/16 18:45, Joseph Myers wrote:
> On Mon, 5 Sep 2016, Marek Polacek wrote:
>
>> Still not sure about other operations. I guess no one would
>> object to warning on bool1 % bool2, but should we warn for
>> bool1 + bool2?
>
> I think boolean addition (with the result interpreted as an integer, not
> converted back to boolean) is perfectly reasonable - counting the number
> of flags that are true, for example (say if there are several conditions
> and it's an error for more than one of them to hold - of course that would
> be bool1 + bool2 + bool3 + bool4, etc.).
>
Yes, that's what I had in mind too. I think I even remember having seen
code like this, which is OK as long as the result is stored in an
integer variable.
But "if (bool1 + bool2)" should be written as "if (bool1 | bool2)",
and "if (bool1 * bool2)" should be written as "if (bool1 & bool2)".
I think a warning for boolean + and * suggesting to use | and &
is justified for clarity.
Bernd.
next prev parent reply other threads:[~2016-09-05 17:01 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-02 15:51 Bernd Edlinger
2016-09-05 14:08 ` Marek Polacek
2016-09-05 14:28 ` Bernd Edlinger
2016-09-05 14:39 ` Marek Polacek
2016-09-05 15:03 ` Bernd Edlinger
2016-09-05 16:46 ` Joseph Myers
2016-09-05 17:03 ` Bernd Edlinger [this message]
2016-09-15 19:55 ` Jeff Law
2016-09-16 9:05 ` Marek Polacek
2016-09-05 15:01 ` Eric Gallager
2016-09-05 15:08 ` Bernd Edlinger
-- strict thread matches above, loose matches on Subject: below --
2016-09-02 15:14 Marek Polacek
2016-09-05 10:51 ` Bernd Schmidt
2016-09-05 10:57 ` Marek Polacek
2016-09-05 16:12 ` Bernd Schmidt
2016-09-05 16:44 ` Sandra Loosemore
2016-09-06 9:08 ` Marek Polacek
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=AM4PR0701MB21625230823BC1CBBBCEF4B9E4E60@AM4PR0701MB2162.eurprd07.prod.outlook.com \
--to=bernd.edlinger@hotmail.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=joseph@codesourcery.com \
--cc=polacek@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).