From patchwork Wed Nov 26 19:21:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 415237 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B10AB1400D5 for ; Thu, 27 Nov 2014 06:21:34 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; q=dns; s=default; b=YiOECTZmXI7wapCA4 uR2NELzAq2dcHiK3oLQwpv9vMB19cqhe7dVu5b8/3WLO4Bt+DOnjd0+7lSiBdMlR aJfmboXDI/KsA6KJ590NeApFcIjNVz27FH3gli9dMfccax/IQL20NfY4pmu14KXo kA+BkNqxyE9tUBNULmGs6RGIho= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; s=default; bh=QMVyKxRafMfmjNhir8fLKQ5 XfHg=; b=L8404WWDYdSjSOSFSCMWqZLVLylX0LNCAl2WSXNi/kkjm67srcTV+D/ PA2bHaB9B43bGVjPTdE1Qp0sFn6XDhX7okFWveovwzxV+3Es9lZljnkuP7ymIdxs i2EkxsZjrtRtpVdLpPuEnhlX/uxlFqKjNZMkMBs37H7CwOG/NuMg= Received: (qmail 3490 invoked by alias); 26 Nov 2014 19:21:27 -0000 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 Received: (qmail 3480 invoked by uid 89); 26 Nov 2014 19:21:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL, BAYES_00, SPF_PASS, T_RP_MATCHES_RCVD 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; Wed, 26 Nov 2014 19:21:26 +0000 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id sAQJLNMp018232 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 26 Nov 2014 19:21:23 GMT Received: from userz7022.oracle.com (userz7022.oracle.com [156.151.31.86]) by ucsinet22.oracle.com (8.14.5+Sun/8.14.5) with ESMTP id sAQJLN3N007637 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 26 Nov 2014 19:21:23 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userz7022.oracle.com (8.14.5+Sun/8.14.4) with ESMTP id sAQJLMUn007611; Wed, 26 Nov 2014 19:21:22 GMT Received: from [192.168.1.4] (/87.16.227.167) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 26 Nov 2014 11:21:22 -0800 Message-ID: <5476282F.9020007@oracle.com> Date: Wed, 26 Nov 2014 20:21:19 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Jason Merrill , "gcc-patches@gcc.gnu.org" Subject: Re: [C++ Patch/RFC] PR 63757 References: <54737F2D.6090504@oracle.com> <5475FEB8.5080505@redhat.com> In-Reply-To: <5475FEB8.5080505@redhat.com> X-IsSubscribed: yes Hi, On 11/26/2014 05:24 PM, Jason Merrill wrote: > On 11/24/2014 01:55 PM, Paolo Carlini wrote: >> in this rejects-valid, as part of build_user_type_conversion_1, >> standard_conversion is called by implicit_conversion with a *null* expr, >> thus the condition in standard_conversion >> >> /* [conv.ptr] >> A null pointer constant can be converted to a pointer type; ... A >> null pointer constant of integral type can be converted to an >> rvalue of type std::nullptr_t. */ >> if ((tcode == POINTER_TYPE || TYPE_PTRMEM_P (to) >> || NULLPTR_TYPE_P (to)) >> && expr && null_ptr_cst_p (expr)) >> conv = build_conv (ck_std, to, conv); >> >> is false and the snippet is rejected. Should we pass a nullptr_node as >> expr in such cases, ie, when handling conversions functions returning >> std::nullptr_t?!? > > I'd prefer to change the test quoted above to not require expr to be > non-null in the case of NULLPTR_TYPE_P. Oh good, I was unsure about that. The below also passes testing. Thanks, Paolo. /////////////////////////// Index: cp/call.c =================================================================== --- cp/call.c (revision 218089) +++ cp/call.c (working copy) @@ -1194,7 +1194,8 @@ standard_conversion (tree to, tree from, tree expr rvalue of type std::nullptr_t. */ if ((tcode == POINTER_TYPE || TYPE_PTRMEM_P (to) || NULLPTR_TYPE_P (to)) - && expr && null_ptr_cst_p (expr)) + && ((expr && null_ptr_cst_p (expr)) + || NULLPTR_TYPE_P (from))) conv = build_conv (ck_std, to, conv); else if ((tcode == INTEGER_TYPE && fcode == POINTER_TYPE) || (tcode == POINTER_TYPE && fcode == INTEGER_TYPE)) Index: testsuite/g++.dg/cpp0x/nullptr33.C =================================================================== --- testsuite/g++.dg/cpp0x/nullptr33.C (revision 0) +++ testsuite/g++.dg/cpp0x/nullptr33.C (working copy) @@ -0,0 +1,19 @@ +// PR c++/63757 +// { dg-do compile { target c++11 } } + +typedef decltype(nullptr) nullptr_t; + +void bar(void*) {} + +struct foo +{ + operator nullptr_t() + { + return nullptr; + } +}; + +int main() +{ + bar(foo()); +}