From patchwork Fri Aug 5 19:10:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 108714 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 E5C1EB6F75 for ; Sat, 6 Aug 2011 05:10:28 +1000 (EST) Received: (qmail 8296 invoked by alias); 5 Aug 2011 19:10:27 -0000 Received: (qmail 8288 invoked by uid 22791); 5 Aug 2011 19:10:26 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, 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; Fri, 05 Aug 2011 19:10:07 +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 p75JA7LV010095 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 5 Aug 2011 15:10:07 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p75JA6rf026515; Fri, 5 Aug 2011 15:10:06 -0400 Received: from [0.0.0.0] (ovpn-113-87.phx2.redhat.com [10.3.113.87]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p75JA5vN003373; Fri, 5 Aug 2011 15:10:05 -0400 Message-ID: <4E3C400C.9020305@redhat.com> Date: Fri, 05 Aug 2011 15:10:04 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:5.0) Gecko/20110719 Thunderbird/5.0 MIME-Version: 1.0 To: gcc-patches List , Paolo Carlini Subject: C++ PATCH to allow VLAs with C++0x auto 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 Paolo asked for GCC to allow deduction of auto from a variable-length array. Since auto doesn't have the issues involved with normal template deduction from VLAs (namely, the type not being link-time constant), this seems reasonable to me. Tested x86_64-pc-linux-gnu, applying to trunk. commit 002b9c9ad8b14999fa87c65f3ccdce772086edd8 Author: Jason Merrill Date: Thu Aug 4 11:48:40 2011 -0400 * pt.c (unify) [TEMPLATE_TYPE_PARM]: Allow VLA for C++0x 'auto'. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 571da6d..10fdced 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -15932,10 +15932,11 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, that were talking about variable-sized arrays (like `int[n]'), rather than arrays of unknown size (like `int[]').) We'll get very confused by such a type since - the bound of the array will not be computable in an - instantiation. Besides, such types are not allowed in - ISO C++, so we can do as we please here. */ - if (variably_modified_type_p (arg, NULL_TREE)) + the bound of the array is not constant, and therefore + not mangleable. Besides, such types are not allowed in + ISO C++, so we can do as we please here. We do allow + them for 'auto' deduction, since that isn't ABI-exposed. */ + if (!is_auto (parm) && variably_modified_type_p (arg, NULL_TREE)) return unify_vla_arg (explain_p, arg); /* Strip typedefs as in convert_template_argument. */ diff --git a/gcc/testsuite/g++.dg/ext/vla11.C b/gcc/testsuite/g++.dg/ext/vla11.C new file mode 100644 index 0000000..8f3be9e --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/vla11.C @@ -0,0 +1,8 @@ +// Test that auto works with VLAs. +// { dg-options -std=c++0x } + +void bar(int n) +{ + float loc2[n]; + auto&& range = loc2; +}