From patchwork Sat Dec 1 19:04:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 203147 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 856862C00A9 for ; Sun, 2 Dec 2012 06:05:08 +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=1354993509; 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=Tf5yt+Ekjcj216V1CfWpIDYMceQ=; b=C18lyw47tG7y+ccVemFqdvGSg9iqQmPueQnK/TpNCyzyDMEs0zCBrvm7UOPJr0 PZ/mLa3Okv8hta630qBeYXcHNkBUrcf5lIDs5gHUrz0CtxKU/PgBxQdl6XIyR8ab 8SgjKntXjAwoSrc8hT2tTAViNl+K28bPJkC20hMQvFoyU= 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=hCtFGu6yqNNoZ9nRA+rbhAahby/5gqXDgFjChKvlh+ee0eCPy2KFk4rRXwzaVd r/iGx43yClN/hsAWU613EUt2NSzn/8rbeVNHmAndF9KIiY4gOwCq03zfnMuNq/N9 fapDQ7o7w2+LkuzIHW3QbCbmx5MxQ2g0Zv10yFeiBf2b8=; Received: (qmail 10002 invoked by alias); 1 Dec 2012 19:05:05 -0000 Received: (qmail 9979 invoked by uid 22791); 1 Dec 2012 19:05:04 -0000 X-SWARE-Spam-Status: No, hits=-5.5 required=5.0 tests=AWL, BAYES_00, KHOP_THREADED, RCVD_IN_HOSTKARMA_NO, RP_MATCHES_RCVD, TW_PM 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; Sat, 01 Dec 2012 19:04:57 +0000 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by aserp1040.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id qB1J4tlU021811 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 1 Dec 2012 19:04:56 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 qB1J4tNj028796 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 1 Dec 2012 19:04:55 GMT Received: from abhmt101.oracle.com (abhmt101.oracle.com [141.146.116.53]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id qB1J4sOD012873; Sat, 1 Dec 2012 13:04:54 -0600 Received: from [192.168.1.4] (/79.53.234.96) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 01 Dec 2012 11:04:54 -0800 Message-ID: <50BA54D4.5070508@oracle.com> Date: Sat, 01 Dec 2012 20:04:52 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Jason Merrill CC: "gcc-patches@gcc.gnu.org" Subject: Re: [C++ Patch] PR 54170 References: <50B91F80.3080100@oracle.com> <50B9A00C.9000408@redhat.com> In-Reply-To: <50B9A00C.9000408@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 Hi, On 12/01/2012 07:13 AM, Jason Merrill wrote: > On 11/30/2012 04:05 PM, Paolo Carlini wrote: >> @@ -219,10 +219,15 @@ cp_convert_to_pointer (tree type, tree expr, tsubs >> - expr = build_int_cst (type, 0); >> + expr = (TREE_SIDE_EFFECTS (expr) >> + ? build_nop (type, expr) >> + : build_int_cst (type, 0)); > > This seems to rely on a nop being sufficient to convert from any null > pointer constant to the appropriate pointer type, which I don't think > is safe if the integer is smaller than a pointer. > > I'm also not sure if we want to rely on nullptr_t expressions actually > having the value 0. Thanks a lot. What about the below? I'm consistently building a COMPOUND_EXPR for the simpler plain pointers too; the hunk for pointers to member functions can be *very* simple: in fact I had already tried this solution but something else was wrong yesterday and seemed not to work, huumpf. Tested x86_64-linux. Thanks again, Paolo. //////////////////// Index: cp/cvt.c =================================================================== --- cp/cvt.c (revision 194020) +++ cp/cvt.c (working copy) @@ -215,16 +215,14 @@ cp_convert_to_pointer (tree type, tree expr, tsubs return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr, 0, /*c_cast_p=*/false, complain); - if (TYPE_PTRDATAMEM_P (type)) - { - /* A NULL pointer-to-member is represented by -1, not by - zero. */ - expr = build_int_cst_type (type, -1); - } - else - expr = build_int_cst (type, 0); + /* A NULL pointer-to-data-member is represented by -1, not by + zero. */ + tree val = (TYPE_PTRDATAMEM_P (type) + ? build_int_cst_type (type, -1) + : build_int_cst (type, 0)); - return expr; + return (TREE_SIDE_EFFECTS (expr) + ? build2 (COMPOUND_EXPR, type, expr, val) : val); } else if (TYPE_PTRMEM_P (type) && INTEGRAL_CODE_P (form)) { Index: cp/typeck.c =================================================================== --- cp/typeck.c (revision 194020) +++ cp/typeck.c (working copy) @@ -7567,7 +7567,7 @@ build_ptrmemfunc (tree type, tree pfn, int force, /* Handle null pointer to member function conversions. */ if (null_ptr_cst_p (pfn)) { - pfn = build_c_cast (input_location, type, nullptr_node); + pfn = build_c_cast (input_location, type, pfn); return build_ptrmemfunc1 (to_type, integer_zero_node, pfn); Index: testsuite/g++.dg/cpp0x/lambda/lambda-nullptr.C =================================================================== --- testsuite/g++.dg/cpp0x/lambda/lambda-nullptr.C (revision 0) +++ testsuite/g++.dg/cpp0x/lambda/lambda-nullptr.C (working copy) @@ -0,0 +1,47 @@ +// PR c++/54170 +// { dg-do run { target c++11 } } + +#include + +struct A; +typedef A* ptr; +typedef int (A::*pmf) (int); +typedef int (A::*pdm); + +int total; + +void add(int n) +{ + total += n; +} + +template +RType Call(Callable native_func, int arg) +{ + return native_func(arg); +} + +template +RType do_test(int delta) +{ + return Call([=](int delta) { add(delta); return nullptr; }, delta); +} + +template +void test() +{ + total = 0; + assert (!do_test(5)); + assert (total == 5); + assert (!do_test(20)); + assert (total == 25); + assert (!do_test(-256)); + assert (total == -231); +} + +int main() +{ + test(); + test(); + test(); +}