This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCHv2] Add a warning for suspicious use of conditional expressions in boolean context
- From: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- To: Denis Campredon <denis dot campredon at gmail dot com>
- Cc: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, Joseph Myers <joseph at codesourcery dot com>, Jason Merrill <jason at redhat dot com>
- Date: Mon, 5 Sep 2016 20:02:00 +0000
- Subject: Re: [PATCHv2] Add a warning for suspicious use of conditional expressions in boolean context
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=softfail (sender IP is 10.152.20.60) smtp.mailfrom=hotmail.de; gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=hotmail.de;
- References: <AM4PR0701MB21624AB3DECA1269E4BBB475E4E50@AM4PR0701MB2162.eurprd07.prod.outlook.com> <AM4PR0701MB2162C862449B51EF27F6AC52E4E70@AM4PR0701MB2162.eurprd07.prod.outlook.com> <CAPWdEev7VW5LT47iPh-0EgAJz5ELEnoZ_snLtg-F5ZR+etLimg@mail.gmail.com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
On 09/05/16 21:23, Denis Campredon wrote:
> Hi,
> Your patch does not emit warning for the following case:
> void f(int j){bool i = j ?: 3;}
>
> But for emit one for
> void f(){bool i = 4 ?: 2;}
> Regards
>
Yes, good point.
It is probably not completely unrealistic
that the middle expression may be accidentally
left out?
The first example is a bit too complicated, because
the warning does only work with integer constants
in the moment, but "j ?: 3" is expanded as "j ? j : 3",
while "4 ?: 2" is expanded as "4 ? 4 : 2" which
matches the check.
I'm not sure if detecting the special case j ?: 3
is worth the effort, but it may be doable.
Should I try that as a follow-up patch?
Thanks
Bernd.