From patchwork Thu Dec 6 14:16:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 204239 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 2129C2C0287 for ; Fri, 7 Dec 2012 01:16:51 +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=1355408212; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=WwQZqbc 2NkLdKbS/zAd36noSml4=; b=w6mdXDGFxwUguAKgzFPkENkePoDkvKZyFB5FIDu PRnIxjAoo1wftCr0agbbV8Or4qq6s1XGOHUNPRb32CJ6uB+xBT+vNxIYQlU0Q1xt gGmB1JqqWNZ0PDp9qWttiDpl+gWTNe6iusa2qo/JXjy+DCAGS4HKgjcRl9mjAuvT oPUI= 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:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=QJX2QhBq6aWwGgI4qXSq6tMFjBCMz2Mdt6fVzSWP1PFUKnKsC0Hka4/Ll9y4E8 1UwXvSh/E6i+G/hZjQq5hb19Kj5mk+heb3BXf7LEfKWMW1Uvv+EoCqiIN1LQYf76 Y3nOgD5ZBWKM5OWWeiFB7Lind/lbsRrfOkuPKzBp8BRls=; Received: (qmail 17248 invoked by alias); 6 Dec 2012 14:16:46 -0000 Received: (qmail 17238 invoked by uid 22791); 6 Dec 2012 14:16:44 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS 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; Thu, 06 Dec 2012 14:16:40 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qB6EGdpK016843 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 6 Dec 2012 09:16:40 -0500 Received: from [10.3.113.167] (ovpn-113-167.phx2.redhat.com [10.3.113.167]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qB6EGdLv020658 for ; Thu, 6 Dec 2012 09:16:39 -0500 Message-ID: <50C0A8C7.9000201@redhat.com> Date: Thu, 06 Dec 2012 09:16:39 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/55564 (ICE with decltype of non-type template parameter) 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 In this PR the problem was that during deduction for the T(&)[N] function parameter we were trying to deduce the array bounds N first, but the type of N depends on T, so we need to deduce T first. This also makes sense from a left-to-right perspective. This broke with my instantiation-dependence patch because decltype(sizeof(T)) was previously folded to size_t, whereas now it is left alone because it is instantiation-dependent; if T is void, the result is an error rather than size_t. Tested x86_64-pc-linux-gnu, applying to trunk. commit 7500f9612ecc0799c72f61a11a213f969e42b17b Author: Jason Merrill Date: Wed Dec 5 11:32:46 2012 -0500 PR c++/55564 * pt.c (unify) [ARRAY_TYPE]: Unify the element type before the bounds. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index e349be6..27084a2 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -16593,6 +16593,8 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, if ((TYPE_DOMAIN (parm) == NULL_TREE) != (TYPE_DOMAIN (arg) == NULL_TREE)) return unify_type_mismatch (explain_p, parm, arg); + RECUR_AND_CHECK_FAILURE (tparms, targs, TREE_TYPE (parm), TREE_TYPE (arg), + strict & UNIFY_ALLOW_MORE_CV_QUAL, explain_p); if (TYPE_DOMAIN (parm) != NULL_TREE) { tree parm_max; @@ -16651,8 +16653,7 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, RECUR_AND_CHECK_FAILURE (tparms, targs, parm_max, arg_max, UNIFY_ALLOW_INTEGER, explain_p); } - return unify (tparms, targs, TREE_TYPE (parm), TREE_TYPE (arg), - strict & UNIFY_ALLOW_MORE_CV_QUAL, explain_p); + return unify_success (explain_p); case REAL_TYPE: case COMPLEX_TYPE: diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype47.C b/gcc/testsuite/g++.dg/cpp0x/decltype47.C new file mode 100644 index 0000000..8e2abaa --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/decltype47.C @@ -0,0 +1,12 @@ +// PR c++/55564 +// { dg-options -std=c++11 } + +template +auto array_size(T(&)[N]) -> decltype(N) { return N; } + +int main() { + int simple[4] = {}; + int result = array_size(simple); + + return result; +}