From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25859 invoked by alias); 4 Aug 2014 16:24:23 -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 25848 invoked by uid 89); 4 Aug 2014 16:24:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 04 Aug 2014 16:24:21 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s74GOI6P004600 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 4 Aug 2014 16:24:19 GMT Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s74GOHYt017494 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 4 Aug 2014 16:24:18 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s74GOHV9017486; Mon, 4 Aug 2014 16:24:17 GMT Received: from [192.168.1.4] (/79.52.198.24) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 04 Aug 2014 09:24:16 -0700 Message-ID: <53DFB3AE.1030706@oracle.com> Date: Mon, 04 Aug 2014 16:24:00 -0000 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch/RFC] PR 43906 Content-Type: multipart/mixed; boundary="------------070809000603040307030300" X-IsSubscribed: yes X-SW-Source: 2014-08/txt/msg00276.txt.bz2 This is a multi-part message in MIME format. --------------070809000603040307030300 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 467 Hi, I suppose we can quickly resolve, one way or another, this rather old issue. Considering: extern void z(); void h() { if ( z != (void*)0 ); } we -Waddress warn in C and we don't in C++, due to the rather subtle differences between null_pointer_constant_p and null_ptr_cst_p. I believe we could as well warn in C++ too, but then I'm afraid we have to handle the case specially, like in the below. What do you think? Thanks! Paolo. ////////////////////// --------------070809000603040307030300 Content-Type: text/plain; charset=UTF-8; name="patch_43906" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch_43906" Content-length: 2442 Index: cp/typeck.c =================================================================== --- cp/typeck.c (revision 213573) +++ cp/typeck.c (working copy) @@ -4353,12 +4353,11 @@ cp_build_binary_op (location_t location, && (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE || code1 == ENUMERAL_TYPE)) short_compare = 1; - else if ((code0 == POINTER_TYPE && code1 == POINTER_TYPE) - || (TYPE_PTRDATAMEM_P (type0) && TYPE_PTRDATAMEM_P (type1))) - result_type = composite_pointer_type (type0, type1, op0, op1, - CPO_COMPARISON, complain); else if ((code0 == POINTER_TYPE || TYPE_PTRDATAMEM_P (type0)) - && null_ptr_cst_p (op1)) + && (null_ptr_cst_p (op1) + /* Handle (void*)0 too. */ + || (TYPE_PTR_P (type1) && VOID_TYPE_P (TREE_TYPE (type1)) + && integer_zerop (op1)))) { if (TREE_CODE (op0) == ADDR_EXPR && decl_with_nonnull_addr_p (TREE_OPERAND (op0, 0))) @@ -4371,7 +4370,10 @@ cp_build_binary_op (location_t location, result_type = type0; } else if ((code1 == POINTER_TYPE || TYPE_PTRDATAMEM_P (type1)) - && null_ptr_cst_p (op0)) + && (null_ptr_cst_p (op0) + /* Handle (void*)0 too. */ + || (TYPE_PTR_P (type0) && VOID_TYPE_P (TREE_TYPE (type0)) + && integer_zerop (op0)))) { if (TREE_CODE (op1) == ADDR_EXPR && decl_with_nonnull_addr_p (TREE_OPERAND (op1, 0))) @@ -4383,6 +4385,10 @@ cp_build_binary_op (location_t location, } result_type = type1; } + else if ((code0 == POINTER_TYPE && code1 == POINTER_TYPE) + || (TYPE_PTRDATAMEM_P (type0) && TYPE_PTRDATAMEM_P (type1))) + result_type = composite_pointer_type (type0, type1, op0, op1, + CPO_COMPARISON, complain); else if (null_ptr_cst_p (op0) && null_ptr_cst_p (op1)) /* One of the operands must be of nullptr_t type. */ result_type = TREE_TYPE (nullptr_node); Index: testsuite/g++.dg/warn/Waddress-1.C =================================================================== --- testsuite/g++.dg/warn/Waddress-1.C (revision 0) +++ testsuite/g++.dg/warn/Waddress-1.C (working copy) @@ -0,0 +1,7 @@ +// PR c++/43906 +// { dg-options "-Waddress" } + +extern void z(); +void f() { if ( z ) z(); } // { dg-warning "address" } +void g() { if ( z != 0 ) z(); } // { dg-warning "address" } +void h() { if ( z != (void*)0 ) z(); } // { dg-warning "address" } --------------070809000603040307030300--