From patchwork Mon Aug 17 20:03:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 508083 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 727D81402B4 for ; Tue, 18 Aug 2015 06:04:20 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=j54mjhWG; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=Vq2XGwaaNCriNYgKO EC3mscGk8RfMf9S2qonnQOEdvldge9FdIFVLDFIkJpuFo50rNpJIF4GnUuieZQ9Z UluZT9kR8h1PBYkOj7CVdeCnIKshDnd+eXlv/leGPFKQ+U0xPDxwfu0ESWD8w4fo cD12QRXbNU4VihdF28X4yAxOfk= 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 :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=yRUVoGhT4kH1Xag0/Rlq3Kl ipWQ=; b=j54mjhWGvYZ7Kpx4oJDSSZHIGi1BPXji7ACKjsj2W3fxWdXcef0Rjqz odlCwAENGcphH203t8XqY6uV4GLMnhaCuttJuuHRoUpw0kfa/UBfMVtL3UL6C0J7 yxh6WrmyjREl0bDIPAsGuyH6skyGaUnls6xsRr5sVu7b7TMB/mnA= Received: (qmail 53830 invoked by alias); 17 Aug 2015 20:04:12 -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 53670 invoked by uid 89); 17 Aug 2015 20:04:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_50, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=no version=3.3.2 X-HELO: aserp1040.oracle.com Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 17 Aug 2015 20:04:06 +0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t7HK43M2021086 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 17 Aug 2015 20:04:03 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.13.8/8.13.8) with ESMTP id t7HK42PV004839 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 17 Aug 2015 20:04:03 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id t7HK428C001580; Mon, 17 Aug 2015 20:04:02 GMT Received: from [192.168.1.4] (/79.37.218.190) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 17 Aug 2015 13:04:02 -0700 Subject: Re: [C++ Patch] PR 67216 ("false is still a null pointer constant") To: Jason Merrill , "gcc-patches@gcc.gnu.org" References: <55D22A8F.8060701@oracle.com> <55D22CFD.9040607@redhat.com> <55D22D73.509@oracle.com> <55D22F04.8040401@redhat.com> <55D2340E.80607@oracle.com> <55D2354C.8070502@redhat.com> From: Paolo Carlini Message-ID: <55D23E2F.4000909@oracle.com> Date: Mon, 17 Aug 2015 22:03:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <55D2354C.8070502@redhat.com> X-IsSubscribed: yes Hi, On 08/17/2015 09:26 PM, Jason Merrill wrote: > On 08/17/2015 03:20 PM, Paolo Carlini wrote: >> On 08/17/2015 08:59 PM, Jason Merrill wrote: >>> On 08/17/2015 02:52 PM, Paolo Carlini wrote: >>>> On 08/17/2015 08:50 PM, Jason Merrill wrote: >>>>> OK. I wonder if we can also drop the STRIP_NOPs on the C++11 path. >>>> You are not alone ;) No, not trivially, without we ICE on pr51313.C. >>> >>> Hmm, that testcase is ill-formed. We ought to reject it, though not >>> ICE. >> Yes, now I see. At the moment however, I have no idea where that >> NOP_EXPR is coming from and whether it would be safe to assume in >> null_ptr_cst_p that one can occur only due to a bug elsewhere... > > I imagine it's coming from built-in folding of isdigit, which is not a > bug. > >> Note >> that integer_zerop calls STRIP_NOPS right at the beginning anyway and >> the ICE comes from TREE_OVERFLOW. > > So I guess null_ptr_cst_p should check for INTEGER_CST before calling > integer_zerop. Yeah, and like in many other places! Thanks. Thus I'm finishing testing the below, which handles correctly pr51313.C too. Note, I'm intentionally leaving the old c++98 path completely alone. Thanks, Paolo. Index: cp/call.c =================================================================== --- cp/call.c (revision 226952) +++ cp/call.c (working copy) @@ -524,22 +524,34 @@ struct z_candidate { bool null_ptr_cst_p (tree t) { + tree type = TREE_TYPE (t); + /* [conv.ptr] A null pointer constant is an integral constant expression (_expr.const_) rvalue of integer type that evaluates to zero or an rvalue of type std::nullptr_t. */ - if (NULLPTR_TYPE_P (TREE_TYPE (t))) + if (NULLPTR_TYPE_P (type)) return true; - if (CP_INTEGRAL_TYPE_P (TREE_TYPE (t))) + + if (cxx_dialect >= cxx11) { /* Core issue 903 says only literal 0 is a null pointer constant. */ - if (cxx_dialect < cxx11) - t = fold_non_dependent_expr (t); + if (TREE_CODE (type) == INTEGER_TYPE) + { + if (TREE_CODE (t) == INTEGER_CST && integer_zerop (t) + && !TREE_OVERFLOW (t)) + return true; + } + } + else if (CP_INTEGRAL_TYPE_P (type)) + { + t = fold_non_dependent_expr (t); STRIP_NOPS (t); if (integer_zerop (t) && !TREE_OVERFLOW (t)) return true; } + return false; } Index: cp/pt.c =================================================================== --- cp/pt.c (revision 226952) +++ cp/pt.c (working copy) @@ -22671,7 +22671,8 @@ resolve_typename_type (tree type, bool only_curren return type; /* If SCOPE isn't the template itself, it will not have a valid TYPE_FIELDS list. */ - if (same_type_p (scope, CLASSTYPE_PRIMARY_TEMPLATE_TYPE (scope))) + if (CLASS_TYPE_P (scope) + && same_type_p (scope, CLASSTYPE_PRIMARY_TEMPLATE_TYPE (scope))) /* scope is either the template itself or a compatible instantiation like X, so look up the name in the original template. */ scope = CLASSTYPE_PRIMARY_TEMPLATE_TYPE (scope); Index: testsuite/g++.dg/cpp0x/decltype63.C =================================================================== --- testsuite/g++.dg/cpp0x/decltype63.C (revision 0) +++ testsuite/g++.dg/cpp0x/decltype63.C (working copy) @@ -0,0 +1,7 @@ +// PR c++/63693 +// { dg-do compile { target c++11 } } + +template +class C{ + T t; + decltype(t)::a:: // { dg-error "expected" } Index: testsuite/g++.dg/cpp0x/nullptr34.C =================================================================== --- testsuite/g++.dg/cpp0x/nullptr34.C (revision 0) +++ testsuite/g++.dg/cpp0x/nullptr34.C (working copy) @@ -0,0 +1,17 @@ +// PR c++/67216 +// { dg-do compile { target c++11 } } + +struct s { + s( long ) {} +}; + +struct t { + t( void * ) {} +}; + +void foo(s) {} +void foo(t) {} + +int main() { + foo(false); +} Index: testsuite/g++.dg/cpp0x/pr51313.C =================================================================== --- testsuite/g++.dg/cpp0x/pr51313.C (revision 226952) +++ testsuite/g++.dg/cpp0x/pr51313.C (working copy) @@ -14,5 +14,5 @@ extern ostream cout; int main() { - cout << isdigit(0); + cout << isdigit(0); // { dg-error "invalid conversion" } } Index: testsuite/g++.dg/warn/Wconversion2.C =================================================================== --- testsuite/g++.dg/warn/Wconversion2.C (revision 226952) +++ testsuite/g++.dg/warn/Wconversion2.C (working copy) @@ -1,3 +1,4 @@ // { dg-options "-Wconversion-null" } void foo(const char *); -void bar() { foo(false); } // { dg-warning "pointer type for argument" } +void bar() { foo(false); } // { dg-warning "pointer type for argument" "" { target { ! c++11 } } } +// { dg-error "cannot convert" "" { target c++11 } 3 } Index: testsuite/g++.dg/warn/Wnull-conversion-1.C =================================================================== --- testsuite/g++.dg/warn/Wnull-conversion-1.C (revision 226952) +++ testsuite/g++.dg/warn/Wnull-conversion-1.C (working copy) @@ -6,10 +6,13 @@ void func1(int* ptr); void func2() { - int* t = false; // { dg-warning "converting 'false' to pointer" } + int* t = false; // { dg-warning "converting 'false' to pointer" "" { target { ! c++11 } } } +// { dg-error "cannot convert" "" { target c++11 } 9 } int* p; - p = false; // { dg-warning "converting 'false' to pointer" } + p = false; // { dg-warning "converting 'false' to pointer" "" { target { ! c++11 } } } +// { dg-error "cannot convert" "" { target c++11 } 12 } int* r = sizeof(char) / 2; // { dg-error "invalid conversion from" "" { target c++11 } } - func1(false); // { dg-warning "converting 'false' to pointer" } + func1(false); // { dg-warning "converting 'false' to pointer" "" { target { ! c++11 } } } +// { dg-error "cannot convert" "" { target c++11 } 15 } int i = NULL; // { dg-warning "converting to non-pointer" } } Index: testsuite/g++.old-deja/g++.other/null3.C =================================================================== --- testsuite/g++.old-deja/g++.other/null3.C (revision 226952) +++ testsuite/g++.old-deja/g++.other/null3.C (working copy) @@ -2,5 +2,6 @@ void x() { - int* p = 1==0; // { dg-warning "converting 'false' to pointer" } + int* p = 1==0; // { dg-warning "converting 'false' to pointer" "" { target { ! c++11 } } } +// { dg-error "cannot convert" "" { target c++11 } 5 } }