From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24492 invoked by alias); 18 Feb 2013 16:28:18 -0000 Received: (qmail 24434 invoked by uid 22791); 18 Feb 2013 16:28:15 -0000 X-SWARE-Spam-Status: No, hits=-3.4 required=5.0 tests=AWL,BAYES_00,FSL_NEW_HELO_USER,RCVD_IN_HOSTKARMA_NO,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 18 Feb 2013 16:28:10 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r1IGS8gA020798 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 18 Feb 2013 16:28:09 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r1IGS8ub006107 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 18 Feb 2013 16:28:08 GMT Received: from abhmt110.oracle.com (abhmt110.oracle.com [141.146.116.62]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r1IGS7b6005149; Mon, 18 Feb 2013 10:28:07 -0600 Received: from [192.168.1.4] (/79.53.235.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 18 Feb 2013 08:28:07 -0800 Message-ID: <51225695.20203@oracle.com> Date: Mon, 18 Feb 2013 16:28:00 -0000 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130105 Thunderbird/17.0.2 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 56373 Content-Type: multipart/mixed; boundary="------------000209000300030405090001" X-IsSubscribed: yes 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 X-SW-Source: 2013-02/txt/msg00851.txt.bz2 This is a multi-part message in MIME format. --------------000209000300030405090001 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 340 Hi, I think submitter is right that with -Wzero-as-null-pointer-constant we want to warn also for zero converted to nullptr_t, not just pointer types. In that case the below is the simplest fix I could figure out, passes testing on x86_64-linux. Otherwise I guess we should simply close the PR. Thanks, Paolo. ////////////////////// --------------000209000300030405090001 Content-Type: text/plain; charset=UTF-8; name="CL_56373" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="CL_56373" Content-length: 318 /cp 2013-02-18 Paolo Carlini PR c++/56373 * cvt.c (ocp_convert): Emit -Wzero-as-null-pointer-constant diagnostics for zero converted to nullptr_t. /testsuite 2013-02-18 Paolo Carlini PR c++/56373 * g++.dg/cpp0x/Wzero-as-null-pointer-constant-2.C: New. --------------000209000300030405090001 Content-Type: text/plain; charset=UTF-8; name="patch_56373" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch_56373" Content-length: 1422 Index: cp/cvt.c =================================================================== --- cp/cvt.c (revision 196099) +++ cp/cvt.c (working copy) @@ -783,7 +783,14 @@ ocp_convert (tree type, tree expr, int convtype, i return ignore_overflows (converted, e); } if (NULLPTR_TYPE_P (type) && e && null_ptr_cst_p (e)) - return nullptr_node; + { + if ((complain & tf_warning) + && c_inhibit_evaluation_warnings == 0 + && !NULLPTR_TYPE_P (TREE_TYPE (e))) + warning_at (loc, OPT_Wzero_as_null_pointer_constant, + "zero as null pointer constant"); + return nullptr_node; + } if (POINTER_TYPE_P (type) || TYPE_PTRMEM_P (type)) return fold_if_not_in_template (cp_convert_to_pointer (type, e, complain)); if (code == VECTOR_TYPE) Index: testsuite/g++.dg/cpp0x/Wzero-as-null-pointer-constant-2.C =================================================================== --- testsuite/g++.dg/cpp0x/Wzero-as-null-pointer-constant-2.C (revision 0) +++ testsuite/g++.dg/cpp0x/Wzero-as-null-pointer-constant-2.C (working copy) @@ -0,0 +1,14 @@ +// PR c++/56373 +// { dg-options "-std=c++11 -Wzero-as-null-pointer-constant" } + +struct shared_ptr +{ + shared_ptr(decltype(nullptr)); +}; + +void f() +{ + shared_ptr a = 0; // { dg-warning "zero as null pointer" } + shared_ptr b(0); // { dg-warning "zero as null pointer" } + shared_ptr c{0}; // { dg-warning "zero as null pointer" } +} --------------000209000300030405090001--