From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11119 invoked by alias); 8 Oct 2002 12:47:47 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 11111 invoked from network); 8 Oct 2002 12:47:41 -0000 Received: from unknown (HELO executor.cambridge.redhat.com) (195.224.55.237) by sources.redhat.com with SMTP; 8 Oct 2002 12:47:41 -0000 Received: from prospero.cambridge.redhat.com (dell-paw-2.cambridge.redhat.com [195.224.55.226]) by executor.cambridge.redhat.com (Postfix) with ESMTP id 0262BABAF8; Tue, 8 Oct 2002 13:47:41 +0100 (BST) Received: by prospero.cambridge.redhat.com (Postfix, from userid 4046) id 270F3F8D08; Tue, 8 Oct 2002 13:47:30 +0100 (BST) To: Neil Booth Cc: nathan@cs.bris.ac.uk, Mark Mitchell , gcc@gcc.gnu.org, nathan@codesourcery.com, gdr@codesourcery.com Subject: Re: Variable-sized types vs. templates References: <1300000.1033752147@localhost> <3DA2A0F6.795BD4F9@acm.org> <20021008123541.GA1691@daikokuya.co.uk> From: Jason Merrill In-Reply-To: <20021008123541.GA1691@daikokuya.co.uk> (Neil Booth's message of "Tue, 8 Oct 2002 13:35:41 +0100") Date: Tue, 08 Oct 2002 07:07:00 -0000 Message-ID: User-Agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i686-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2002-10/txt/msg00466.txt.bz2 On Tue, 8 Oct 2002 13:35:41 +0100, Neil Booth wrote: > Jason Merrill wrote:- > >> Similarly, I think it's appropriate to say that neither VLA nor VM types >> are valid template type arguments. I'd also say that a VLA is not a valid >> type for a struct member; I don't understand why C99 seems to allow that. >> Perhaps it wants to allow it so that uses in different functions can have >> different sizes, but that seems incompatible with the stronger C++ model of >> struct types. > I think they wanted to formalize hacks like: > > /* Chained list of answers to an assertion. */ > struct answer > { > struct answer *next; > unsigned int count; > cpp_token first[1]; > }; > > Where first is an array of size determined at run time. But first isn't a VLA. To actually use a VLA in a struct would mean an example like int foo_length; struct foo { int arr[foo_length]; }; void f () { foo_length = 42; { foo bar; bar.arr[12] = 24; } } which seems rather more ugly than the 'struct hack' you refer to. And, since it can only be used for local variables, rather useless. Now that I think of it, this is probably more what they had in mind: void f (int n) { struct foo { ...; int arr[n]; } bar; } So, to refine my earlier suggestion, in C++ I'd prohibit VLAs in types with linkage. A local class such as this is already an invalid template type parm. Jason