From patchwork Tue Mar 8 21:40:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 86038 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 71C06B6EEC for ; Wed, 9 Mar 2011 08:40:17 +1100 (EST) Received: (qmail 3229 invoked by alias); 8 Mar 2011 21:40:15 -0000 Received: (qmail 3213 invoked by uid 22791); 8 Mar 2011 21:40:13 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 08 Mar 2011 21:40:09 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p28Le8PO006981 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 8 Mar 2011 16:40:08 -0500 Received: from [127.0.0.1] (ovpn-113-58.phx2.redhat.com [10.3.113.58]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p28Le75k003823; Tue, 8 Mar 2011 16:40:07 -0500 Message-ID: <4D76A237.4010000@redhat.com> Date: Tue, 08 Mar 2011 16:40:07 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc-patches List CC: Dodji Seketeli Subject: Re: C++ PATCH for c++/47705 (ICE with non-pointer argument to pointer template parameter) References: <4D766697.2020507@redhat.com> In-Reply-To: <4D766697.2020507@redhat.com> 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 On 03/08/2011 12:25 PM, Jason Merrill wrote: > We were asserting that any argument to a non-type template parameter of > pointer type must be an address. Which is true of valid code (apart from > null pointer values), but not necessarily of invalid code, where we > should complain rather than crash. Dodji had an idea for a different way to fix this crash: avoid the call to decay_conversion which adds the NOP to convert 'const int' to 'int' by limiting it to the case where the argument is an array. I think I like this way better. Tested x86_64-pc-linux-gnu, applied to trunk. commit c9e36778318c240777889a403693e95488a13b6d Author: Jason Merrill Date: Tue Mar 8 14:02:21 2011 -0500 PR c++/47705 * pt.c (convert_nontype_argument): Only call decay_conversion on arrays. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index cda9df8..2ca2cd0 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -5314,7 +5314,8 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) /* Add the ADDR_EXPR now for the benefit of value_dependent_expression_p. */ - if (TYPE_PTROBV_P (type)) + if (TYPE_PTROBV_P (type) + && TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE) expr = decay_conversion (expr); /* If we are in a template, EXPR may be non-dependent, but still @@ -5369,20 +5370,15 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) qualification conversion. Let's strip everything. */ else if (TYPE_PTROBV_P (type)) { - tree sub = expr; - STRIP_NOPS (sub); - if (TREE_CODE (sub) == ADDR_EXPR) - { - gcc_assert (TREE_CODE (TREE_TYPE (sub)) == POINTER_TYPE); - /* Skip the ADDR_EXPR only if it is part of the decay for - an array. Otherwise, it is part of the original argument - in the source code. */ - if (TREE_CODE (TREE_TYPE (TREE_OPERAND (sub, 0))) == ARRAY_TYPE) - expr = TREE_OPERAND (sub, 0); - else - expr = sub; - expr_type = TREE_TYPE (expr); - } + STRIP_NOPS (expr); + gcc_assert (TREE_CODE (expr) == ADDR_EXPR); + gcc_assert (TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE); + /* Skip the ADDR_EXPR only if it is part of the decay for + an array. Otherwise, it is part of the original argument + in the source code. */ + if (TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == ARRAY_TYPE) + expr = TREE_OPERAND (expr, 0); + expr_type = TREE_TYPE (expr); } } diff --git a/gcc/testsuite/g++.dg/template/nontype21.C b/gcc/testsuite/g++.dg/template/nontype21.C index c0f5319..69cab54 100644 --- a/gcc/testsuite/g++.dg/template/nontype21.C +++ b/gcc/testsuite/g++.dg/template/nontype21.C @@ -4,4 +4,4 @@ template class Something { }; extern char const xyz; -class SomethingElse:public Something { }; // { dg-error "const char *" } +class SomethingElse:public Something { }; // { dg-error "xyz. is a variable" }