From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 60407 invoked by alias); 5 Sep 2016 14:08:27 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 60397 invoked by uid 89); 5 Sep 2016 14:08:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.2 spammy=H*c:Windows-1252, build_unary_op, Something, Hx-spam-relays-external:sk:EUR03-V X-HELO: COL004-OMC2S2.hotmail.com Received: from col004-omc2s2.hotmail.com (HELO COL004-OMC2S2.hotmail.com) (65.55.34.76) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Sep 2016 14:08:25 +0000 Received: from EUR03-VE1-obe.outbound.protection.outlook.com ([65.55.34.71]) by COL004-OMC2S2.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Mon, 5 Sep 2016 07:08:24 -0700 Received: from VE1EUR03FT018.eop-EUR03.prod.protection.outlook.com (10.152.18.51) by VE1EUR03HT004.eop-EUR03.prod.protection.outlook.com (10.152.18.162) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.6; Mon, 5 Sep 2016 14:08:21 +0000 Received: from AM4PR0701MB2162.eurprd07.prod.outlook.com (10.152.18.58) by VE1EUR03FT018.mail.protection.outlook.com (10.152.18.135) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.6 via Frontend Transport; Mon, 5 Sep 2016 14:08:21 +0000 Received: from AM4PR0701MB2162.eurprd07.prod.outlook.com ([10.167.132.147]) by AM4PR0701MB2162.eurprd07.prod.outlook.com ([10.167.132.147]) with mapi id 15.01.0599.016; Mon, 5 Sep 2016 14:08:20 +0000 From: Bernd Edlinger To: Marek Polacek CC: Joseph Myers , "gcc-patches@gcc.gnu.org" Subject: Re: C/C++ PATCH for c/77423 (bogus warning with -Wlogical-not-parentheses) Date: Mon, 05 Sep 2016 14:28:00 -0000 Message-ID: References: <20160905120329.GC19950@redhat.com> In-Reply-To: <20160905120329.GC19950@redhat.com> authentication-results: spf=softfail (sender IP is 10.152.18.58) smtp.mailfrom=hotmail.de; redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=hotmail.de; received-spf: SoftFail (protection.outlook.com: domain of transitioning hotmail.de discourages use of 10.152.18.58 as permitted sender) x-ms-exchange-messagesentrepresentingtype: 1 x-eopattributedmessage: 0 x-microsoft-exchange-diagnostics: 1;VE1EUR03HT004;6:tyJNgpAXPrrsIh5YtXVoYZaota9r1CSm1vNLM2zFq7xts3bFjflB7EGXVsahFQYwd/7OWRY1zyIC2IZ9tp9kW7MUM4krpN86asjoEMsSzbAdv3iiB8ZPF0aS/tcXAoPXxAFnBX8HHjpIo7yel8OD30D8hwWgk2+VW+VLxbRwVYhq1EoCGhxGo+KaI35KbHJEAoQ3P5z4SKACn4cGYHdKeoASXQrSPT96QOw9qXMO/Q7/t0qXij5UT3zcVTZZRdxl4YF20IvNwwTdwgq2jKeyoetpMWj5bOjg77Kds1MWk2k95qbKDtoXUWhQwQ+419Q7;5:h3YO5M0pvkCRnsApZomdr+dJKD4l3mvfajMugPAJSz52N2BsrHzhMXJoDSLkVOgGFPaypuvwLZp6FDJWFWMJImanLP9vtG6DaY0g8XA2S0qqm1Bvlb1+QI/rLebdEBxAVYoZbzT8uUG9Hw1zBhattw==;24:iwo25sOGBiVXp6TfPvgdr3rodLUJ5oHHarKh/d26rgFtjZ2/aAg4Ed6cdxwY9UBeEmEf7VRQVRB/K3bNU7C7qdTO4N8QiB0YnyundigJO2o=;7:2U6DBaQH2/evwXODpBBj4D2qJKK4uU7FVYdA4ETyauUd7I3lnvXOsFugfhI7D1aKis05y8/c3g0ySSSDlvnQKSkTgEkIJfEANgU+2nPi94cXDPCj1I8WGNSCcABqSJwd16o+5HIbUU+gZLxNC0UbvKqlki7peNA8UDG/WUa6ODFwKPQc0Lplr+nhtlnr3yVDj+XPyBhRm0/b0S8wtxLP4kJrFbYovwmMs/N8zlvzO3rqvkxOE43obWiC7lgFHBnO x-forefront-antispam-report: EFV:NLI;SFV:NSPM;SFS:(10019020)(98900003);DIR:OUT;SFP:1102;SCL:1;SRVR:VE1EUR03HT004;H:AM4PR0701MB2162.eurprd07.prod.outlook.com;FPR:;SPF:None;LANG:en; x-ms-office365-filtering-correlation-id: 6b48b31e-be4c-4d58-e1a0-08d3d59616c3 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(1601124038)(1603103081)(1601125047);SRVR:VE1EUR03HT004; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(432015012)(82015046);SRVR:VE1EUR03HT004;BCL:0;PCL:0;RULEID:;SRVR:VE1EUR03HT004; x-forefront-prvs: 005671E15D spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="Windows-1252" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Sep 2016 14:08:20.5659 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR03HT004 X-SW-Source: 2016-09/txt/msg00203.txt.bz2 On 09/05/16 14:03, Marek Polacek wrote: > On Fri, Sep 02, 2016 at 03:51:49PM +0000, Bernd Edlinger wrote: >> Hi, >> >> > + r +=3D !a =3D=3D ~b; >> > + r +=3D !a =3D=3D ~(int) b; >> >> I don't understand why ~b should not be warned at -Wall. > > Yeah, there was an RFE for this but I'm not finding it. > I certainly agree that the warning is compeletely misleading here: test.c: In function 'f': test.c:10:11: warning: logical not is only applied to the left hand side=20 of comparison [-Wlogical-not-parentheses] r +=3D !a =3D=3D ~b; ^~ test.c:10:8: note: add parentheses around left hand side expression to=20 silence this warning r +=3D !a =3D=3D ~b; ^~ ( ) this will not fix it, but make it worse. I think a better warning would be warning: ~ on boolean value, did you mean ! ? >> Frankly I don't even understand why the above statements are >> completely optimized away. >> >> r +=3D !a =3D=3D ~b; >> is optimized away, but >> >> b =3D ~b; >> r +=3D !a =3D=3D b; >> >> Is not. Why? > > Something in ccp I suppose. But I didn't investigate closely because > it's not really relevant to this patch, sorry. > Yes, I think the problem is that ~ on bool maps [0:1] to [-1:-2] and thus the result is no longer boolean. But probaby the assignment normalizes the result again: b =3D ~b; has the effect of setting b =3D 1. A warning for "~ on boolean" would not be too difficult, but making a fix-it will probably need more work: Index: gcc/c/c-typeck.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/c/c-typeck.c (revision 239971) +++ gcc/c/c-typeck.c (working copy) @@ -4192,6 +4192,17 @@ build_unary_op (location_t location, break; case BIT_NOT_EXPR: + { + tree e =3D arg; + + /* Warn if the condition has boolean value. */ + while (TREE_CODE (e) =3D=3D COMPOUND_EXPR) + e =3D TREE_OPERAND (e, 1); + + if (TREE_CODE (TREE_TYPE (arg)) =3D=3D BOOLEAN_TYPE + || truth_value_p (TREE_CODE (e))) + warning(0, "~ on boolean value, did you mean ! ?"); + } /* ~ works on integer types and non float vectors. */ if (typecode =3D=3D INTEGER_TYPE || (typecode =3D=3D VECTOR_TYPE Index: gcc/cp/typeck.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/cp/typeck.c (revision 239971) +++ gcc/cp/typeck.c (working copy) @@ -5839,6 +5839,8 @@ cp_build_unary_op (enum tree_code code, tree xarg, break; case BIT_NOT_EXPR: + if (TREE_CODE (TREE_TYPE (arg)) =3D=3D BOOLEAN_TYPE) + warning (0, "~ on boolean value, did you mean ! ?"); if (TREE_CODE (TREE_TYPE (arg)) =3D=3D COMPLEX_TYPE) { code =3D CONJ_EXPR; Bernd.