From patchwork Tue Feb 19 15:59:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 221717 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 5FB242C02F2 for ; Wed, 20 Feb 2013 03:00:19 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1361894420; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Message-ID:Date:From:User-Agent:MIME-Version: To:CC:Subject:References:In-Reply-To:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=zViqeuBPDEnYevuNYnan08dAqjA=; b=n3UMzdCDvmGGU362T8LTdtRY+I2tXLr6Sru8kkhysZj1fGJU3uHa3SukEQaL/b PpN5ki6EdAzbPPNq7PHzH7SqrThEi0hMZRu6Q7Y9bu2iZvCxrMPaqIX3CkEZwxbj Fzt8u8LueibdyGNnqM+X661hPSnaaLJhPtPwrIOFsqno8= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=UvepMEVxfH4hzyOBkLtDxv0PO1E2S7fOFxiJEW5JYCxTWkcx/B/XTWz7cZTzOY wNL3ZoLQ6XBnoQnK9ISboqVBKdf/fPTrVgdSMXvXpQPEUPHBYMhS0TBNYlQFdBh5 qZCwRmmMZ62fnBDBoUnB4My3ulybwUsEKY2mGgVJ9mpB0=; Received: (qmail 4878 invoked by alias); 19 Feb 2013 16:00:13 -0000 Received: (qmail 4849 invoked by uid 22791); 19 Feb 2013 16:00:11 -0000 X-SWARE-Spam-Status: No, hits=-4.5 required=5.0 tests=AWL, BAYES_40, KHOP_THREADED, RCVD_IN_HOSTKARMA_NO, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 19 Feb 2013 16:00:00 +0000 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r1JFxwge006959 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 19 Feb 2013 15:59:59 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r1JFxvCn024859 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 19 Feb 2013 15:59:58 GMT Received: from abhmt106.oracle.com (abhmt106.oracle.com [141.146.116.58]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r1JFxvj9017687; Tue, 19 Feb 2013 09:59:57 -0600 Received: from [192.168.1.4] (/79.40.56.65) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 19 Feb 2013 07:59:57 -0800 Message-ID: <5123A17A.3010205@oracle.com> Date: Tue, 19 Feb 2013 16:59:54 +0100 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: Re: [C++ Patch] PR 56373 References: <51225695.20203@oracle.com> In-Reply-To: <51225695.20203@oracle.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 ... in case, we may want to do something like the below too. Thanks, Paolo. /////////////////// Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 196136) +++ cp/cp-tree.h (working copy) @@ -5834,6 +5834,7 @@ extern bool cast_valid_in_integral_constant_expres extern bool cxx_type_hash_eq (const_tree, const_tree); extern void cxx_print_statistics (void); +extern bool maybe_warn_zero_as_null_pointer_constant (tree, location_t); /* in ptree.c */ extern void cxx_print_xnode (FILE *, tree, int); Index: cp/cvt.c =================================================================== --- cp/cvt.c (revision 196136) +++ cp/cvt.c (working copy) @@ -203,11 +203,8 @@ cp_convert_to_pointer (tree type, tree expr, tsubs if (null_ptr_cst_p (expr)) { - if ((complain & tf_warning) - && c_inhibit_evaluation_warnings == 0 - && !NULLPTR_TYPE_P (TREE_TYPE (expr))) - warning_at (loc, OPT_Wzero_as_null_pointer_constant, - "zero as null pointer constant"); + if (complain & tf_warning) + maybe_warn_zero_as_null_pointer_constant (expr, loc); if (TYPE_PTRMEMFUNC_P (type)) return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr, 0, @@ -783,7 +780,11 @@ 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) + maybe_warn_zero_as_null_pointer_constant (e, loc); + 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: cp/decl.c =================================================================== --- cp/decl.c (revision 196136) +++ cp/decl.c (working copy) @@ -10861,15 +10861,10 @@ check_default_argument (tree decl, tree arg) --cp_unevaluated_operand; if (warn_zero_as_null_pointer_constant - && c_inhibit_evaluation_warnings == 0 && TYPE_PTR_OR_PTRMEM_P (decl_type) && null_ptr_cst_p (arg) - && !NULLPTR_TYPE_P (TREE_TYPE (arg))) - { - warning (OPT_Wzero_as_null_pointer_constant, - "zero as null pointer constant"); - return nullptr_node; - } + && maybe_warn_zero_as_null_pointer_constant (arg, input_location)) + return nullptr_node; /* [dcl.fct.default] Index: cp/tree.c =================================================================== --- cp/tree.c (revision 196136) +++ cp/tree.c (working copy) @@ -3939,6 +3939,21 @@ cp_tree_operand_length (const_tree t) return TREE_OPERAND_LENGTH (t); } } + +/* Implement -Wzero_as_null_pointer_constant. Return true if the + conditions for the warning hold, false otherwise. */ +bool +maybe_warn_zero_as_null_pointer_constant (tree expr, location_t loc) +{ + if (c_inhibit_evaluation_warnings == 0 + && !NULLPTR_TYPE_P (TREE_TYPE (expr))) + { + warning_at (loc, OPT_Wzero_as_null_pointer_constant, + "zero as null pointer constant"); + return true; + } + return false; +} #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007) /* Complain that some language-specific thing hanging off a tree Index: cp/typeck.c =================================================================== --- cp/typeck.c (revision 196136) +++ cp/typeck.c (working copy) @@ -4293,13 +4293,10 @@ cp_build_binary_op (location_t location, delta0, integer_one_node, complain); - - if ((complain & tf_warning) - && c_inhibit_evaluation_warnings == 0 - && !NULLPTR_TYPE_P (TREE_TYPE (op1))) - warning (OPT_Wzero_as_null_pointer_constant, - "zero as null pointer constant"); + if (complain & tf_warning) + maybe_warn_zero_as_null_pointer_constant (op1, input_location); + e2 = cp_build_binary_op (location, EQ_EXPR, e2, integer_zero_node, complain); 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" } +}