From patchwork Fri Nov 4 01:51:16 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 123555 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 7FB39B6F67 for ; Fri, 4 Nov 2011 12:52:04 +1100 (EST) Received: (qmail 1368 invoked by alias); 4 Nov 2011 01:51:58 -0000 Received: (qmail 1355 invoked by uid 22791); 4 Nov 2011 01:51:53 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from acsinet15.oracle.com (HELO acsinet15.oracle.com) (141.146.126.227) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 04 Nov 2011 01:51:35 +0000 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by acsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id pA41pUIi016084 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 4 Nov 2011 01:51:34 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id pA41pTSH020967 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 4 Nov 2011 01:51:30 GMT Received: from abhmt117.oracle.com (abhmt117.oracle.com [141.146.116.69]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id pA41pOLH007134; Thu, 3 Nov 2011 20:51:24 -0500 Received: from [192.168.1.4] (/79.52.194.110) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 03 Nov 2011 18:51:24 -0700 Message-ID: <4EB34514.6060504@oracle.com> Date: Fri, 04 Nov 2011 02:51:16 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: Jason Merrill CC: "gcc-patches@gcc.gnu.org" Subject: Re: [C++ Patch / RFC] PR 48420 References: <4EB1F391.4010802@oracle.com> <4EB2BBFD.5080604@redhat.com> In-Reply-To: <4EB2BBFD.5080604@redhat.com> X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On 11/03/2011 05:06 PM, Jason Merrill wrote: > I'd rather use maybe_constant_value here, but I think you don't need > to check the actual value at all; if we have decided that there is a > conversion from bool to pointer, it must be a null pointer constant, > and so false. Ah! Thanks for the explanation, thus it seems even simpler than I thought yesterday. I just booted and tested the below on x86_64-linux. Ok? Thanks again, Paolo. /////////////// /cp 2011-11-04 Paolo Carlini PR c++/48420 * call.c (conversion_null_warnings): For 'false' to NULL pointer, just check that TREE_TYPE (expr) is a BOOLEAN_TYPE. /testsuite 2011-11-04 Paolo Carlini PR c++/48420 * g++.dg/warn/Wconversion-null-3.C: New. Index: testsuite/g++.dg/warn/Wconversion-null-3.C =================================================================== --- testsuite/g++.dg/warn/Wconversion-null-3.C (revision 0) +++ testsuite/g++.dg/warn/Wconversion-null-3.C (revision 0) @@ -0,0 +1,8 @@ +// PR c++/48420 + +void foo(int* p); + +void bar() { + const bool kDebugMode = false; + foo(kDebugMode); // { dg-warning "converting 'false'" } +} Index: cp/call.c =================================================================== --- cp/call.c (revision 180920) +++ cp/call.c (working copy) @@ -5544,7 +5544,8 @@ conversion_null_warnings (tree totype, tree expr, } /* Issue warnings if "false" is converted to a NULL pointer */ - else if (expr == boolean_false_node && TYPE_PTR_P (totype)) + else if (TREE_CODE (TREE_TYPE (expr)) == BOOLEAN_TYPE + && TYPE_PTR_P (totype)) { if (fn) warning_at (input_location, OPT_Wconversion_null,