From patchwork Tue Jun 3 16:55:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 355601 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 021B2140091 for ; Wed, 4 Jun 2014 02:58:53 +1000 (EST) 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=yotGFpD1Jd7fWHHa3 EElgwL9HdTxeSMsCxGvgzqcBUYjwZOvUwCIjLgBuepcjlCsZqf8eU0I0iJPArjjo LPR3aaeZ49trcc0isM8igVr337wJsYAcUG1bb0ThesTTQ9LUrUwtH6vU5+nPMowL 2pa1R3O86mTuTxjtCQvjq+zAyo= 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=aYGi+tMGGzqyO0gkdBM5Qpb YxHw=; b=IXQbzHMRjSK2x08KPHi/NP4Sf13QlGWSjpHWPlbAtruQeB3/rFwmvCf 2gjmo8ogxLBa+aef5u7w6seOALzKhkGV/ZZAv3yp7DjXk6ZETF/x3hJvkV+m87FM /qnBIvuSuxGO0LOIL8YgnMMabFLfVUD02QtaaZjD6g4ZixMSC/mo= Received: (qmail 4827 invoked by alias); 3 Jun 2014 16:58:46 -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 4818 invoked by uid 89); 3 Jun 2014 16:58:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.7 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS 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; Tue, 03 Jun 2014 16:58:44 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s53GwfV6016317 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 3 Jun 2014 16:58:42 GMT Received: from userz7022.oracle.com (userz7022.oracle.com [156.151.31.86]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s53Gwe9c009180 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 3 Jun 2014 16:58:41 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userz7022.oracle.com (8.14.5+Sun/8.14.4) with ESMTP id s53GwdQ3010446; Tue, 3 Jun 2014 16:58:39 GMT Received: from [192.168.1.4] (/79.33.215.66) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 03 Jun 2014 09:58:38 -0700 Message-ID: <538DFE15.3020800@oracle.com> Date: Tue, 03 Jun 2014 18:55:49 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Jason Merrill , "gcc-patches@gcc.gnu.org" Subject: Re: [C++ Patch] PR 52174 aka DR 1423 References: <538DDBF6.70102@oracle.com> <538DE397.80707@redhat.com> <538DE8B0.6060404@oracle.com> <538DECA6.9020207@redhat.com> In-Reply-To: <538DECA6.9020207@redhat.com> X-IsSubscribed: yes Hi, On 06/03/2014 05:41 PM, Jason Merrill wrote: > On 06/03/2014 11:24 AM, Paolo Carlini wrote: >> + if (NULLPTR_TYPE_P (from) && (flags & LOOKUP_ONLYCONVERTING)) >> + conv->bad_p = true; > > Thanks. What kind of error message do we get with this change? Would > adding something to convert_like_real provide a more helpful diagnostic? We get the default: invalid conversion from ‘std::nullptr_t’ to ‘bool’ [-fpermissive] Maybe something like the below then?!? Thanks, Paolo. ///////////////////// Index: gcc/cp/call.c =================================================================== --- gcc/cp/call.c (revision 211162) +++ gcc/cp/call.c (working copy) @@ -1311,10 +1311,10 @@ standard_conversion (tree to, tree from, tree expr { /* [conv.bool] - An rvalue of arithmetic, unscoped enumeration, pointer, or - pointer to member type can be converted to an rvalue of type - bool. ... An rvalue of type std::nullptr_t can be converted - to an rvalue of type bool; */ + A prvalue of arithmetic, unscoped enumeration, pointer, or pointer + to member type can be converted to a prvalue of type bool. ... + For direct-initialization (8.5 [dcl.init]), a prvalue of type + std::nullptr_t can be converted to a prvalue of type bool; */ if (ARITHMETIC_TYPE_P (from) || UNSCOPED_ENUM_P (from) || fcode == POINTER_TYPE @@ -1328,6 +1328,8 @@ standard_conversion (tree to, tree from, tree expr && conv->rank < cr_pbool) || NULLPTR_TYPE_P (from)) conv->rank = cr_pbool; + if (NULLPTR_TYPE_P (from) && (flags & LOOKUP_ONLYCONVERTING)) + conv->bad_p = true; return conv; } @@ -6062,6 +6064,14 @@ convert_like_real (conversion *convs, tree expr, t expr = CONSTRUCTOR_ELT (expr, 0)->value; } + /* Give a helpful error if this is bad because a conversion to bool + from std::nullptr_t requires direct-initialization. */ + if (NULLPTR_TYPE_P (TREE_TYPE (expr)) + && TREE_CODE (totype) == BOOLEAN_TYPE) + complained = permerror (loc, "converting to %qT from %qT requires " + "direct-initialization", + totype, TREE_TYPE (expr)); + for (; t ; t = next_conversion (t)) { if (t->kind == ck_user && t->cand->reason) Index: gcc/testsuite/g++.dg/cpp0x/nullptr17.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/nullptr17.C (revision 211162) +++ gcc/testsuite/g++.dg/cpp0x/nullptr17.C (working copy) @@ -1,6 +1,7 @@ // { dg-do compile { target c++11 } } -// Test that bool is a better overload match than int +// Used to test that bool is a better overload match than int +// Updated for DR 1423 template struct tType_equal; template struct tType_equal { typedef void type; }; @@ -16,7 +17,7 @@ bool i( bool ); void test_i() { // Overload to bool, not int - type_equal(i(nullptr)); + type_equal(i(nullptr)); // { dg-error "direct" } decltype(nullptr) mynull = 0; - type_equal(i(mynull)); + type_equal(i(mynull)); // { dg-error "direct" } } Index: gcc/testsuite/g++.dg/cpp0x/nullptr31.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/nullptr31.C (revision 0) +++ gcc/testsuite/g++.dg/cpp0x/nullptr31.C (working copy) @@ -0,0 +1,11 @@ +// DR 1423, PR c++/52174 +// { dg-do compile { target c++11 } } + +bool b1 = nullptr; // { dg-error "direct" } + +bool b2(nullptr); +bool b3{nullptr}; + +int i1 = nullptr; // { dg-error "cannot convert" } +int i2(nullptr); // { dg-error "cannot convert" } +int i3{nullptr}; // { dg-error "cannot convert" } Index: gcc/testsuite/g++.dg/cpp0x/sfinae-nullptr1.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/sfinae-nullptr1.C (revision 0) +++ gcc/testsuite/g++.dg/cpp0x/sfinae-nullptr1.C (working copy) @@ -0,0 +1,18 @@ +// DR 1423, PR c++/52174 +// { dg-do compile { target c++11 } } + +template +T&& make(); + +template +void sink(T); + +template(make())) +> +auto f(int) -> char(&)[1]; + +template +auto f(...) -> char(&)[2]; + +static_assert(sizeof(f(0)) != 1, ""); Index: libstdc++-v3/testsuite/20_util/is_assignable/value.cc =================================================================== --- libstdc++-v3/testsuite/20_util/is_assignable/value.cc (revision 211151) +++ libstdc++-v3/testsuite/20_util/is_assignable/value.cc (working copy) @@ -174,7 +174,7 @@ static_assert(!std::is_assignable::valu static_assert(std::is_assignable::value, "Error"); static_assert(std::is_assignable::value, "Error"); static_assert(std::is_assignable::value, "Error"); -static_assert(std::is_assignable::value, "Error"); +static_assert(!std::is_assignable::value, "Error"); static_assert(std::is_assignable::value, "Error");