From patchwork Fri Mar 11 16:58:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 86436 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 19A7FB6F10 for ; Sat, 12 Mar 2011 03:58:30 +1100 (EST) Received: (qmail 11132 invoked by alias); 11 Mar 2011 16:58:27 -0000 Received: (qmail 11121 invoked by uid 22791); 11 Mar 2011 16:58:25 -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; Fri, 11 Mar 2011 16:58:17 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2BGwFK7002940 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 11 Mar 2011 11:58:15 -0500 Received: from [127.0.0.1] (ovpn-113-58.phx2.redhat.com [10.3.113.58]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p2BGwF6e023487 for ; Fri, 11 Mar 2011 11:58:15 -0500 Message-ID: <4D7A54A6.1000206@redhat.com> Date: Fri, 11 Mar 2011 11:58:14 -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 Subject: C++ PATCH for c++/47808 (C++0x ICE with VLA in template) 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 The problem here was that we were tsubsting twice: first we did fold_non_dependent_expr in compute_array_index_type to try and get a constant, then because we didn't end up with a constant, we later tsubst it again. So if it didn't work out the first time, we should revert to the unfolded form. Tested x86_64-pc-linux-gnu, applied to trunk. commit 46d65806fd1f7532dc078887c8dea840ee39dcb6 Author: Jason Merrill Date: Fri Mar 11 11:08:00 2011 -0500 PR c++/47808 * decl.c (compute_array_index_type): Discard folding if it didn't produce a constant. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 93c1848..f9d90ad 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7523,6 +7523,8 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain) } size = maybe_constant_value (size); + if (!TREE_CONSTANT (size)) + size = osize; } if (error_operand_p (size)) diff --git a/gcc/testsuite/g++.dg/cpp0x/regress/array1.C b/gcc/testsuite/g++.dg/cpp0x/regress/array1.C new file mode 100644 index 0000000..629ab41 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/regress/array1.C @@ -0,0 +1,16 @@ +// PR c++/47808 +// { dg-options -std=c++0x } + +template +inline T abs (T const & x) { return x; } + +template +void f (T) +{ + typedef int ai[(abs(0.1) > 0) ? 1 : -1]; +} + +int main() +{ + f(1); +}