From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32342 invoked by alias); 10 Jun 2008 18:56:58 -0000 Received: (qmail 32334 invoked by uid 22791); 10 Jun 2008 18:56:57 -0000 X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.33.17) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 10 Jun 2008 18:56:40 +0000 Received: from spaceape23.eur.corp.google.com (spaceape23.eur.corp.google.com [172.28.16.75]) by smtp-out.google.com with ESMTP id m5AIuD5w021378; Tue, 10 Jun 2008 19:56:14 +0100 Received: from localhost.localdomain.google.com (dhcp-172-18-116-187.corp.google.com [172.18.116.187]) (authenticated bits=0) by spaceape23.eur.corp.google.com with ESMTP id m5AIuAbr024499 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 10 Jun 2008 19:56:13 +0100 To: Alan Mackenzie Cc: gcc@gcc.gnu.org Subject: Re: Help requested on C++ template syntax (for Emacs development). References: <20080610183707.GB4844@muc.de> From: Ian Lance Taylor Date: Tue, 10 Jun 2008 18:56:00 -0000 In-Reply-To: <20080610183707.GB4844@muc.de> (Alan Mackenzie's message of "Tue\, 10 Jun 2008 18\:37\:07 +0000") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2008-06/txt/msg00256.txt.bz2 Alan Mackenzie writes: > I'm thinking of things like > > foo (a < b, c > d); > > I think this is unambiguously a function call with 2 parameters, the > expressions "a < b" and "c > d". It cannot be be one with 1 parameter > beginning with the template invocation "a < b , c >". Or can it? No, it can't be, because a is a type. The result would be foo(TYPE d), which can not be a function call. On the other hand, if there were a type before foo then this would be a function declaration. For example, this is valid C++ code: template class a; int fn(int d, int e) { const int b = 1; const int c = 2; typedef int f; f foo (int, int); f foo (a < b, c > d); foo (e < b, c > d); } The line "f foo (a < b, c > d);" uses a template, the line "foo (e < b, c > d);" does not. I rather doubt that you can purely syntactically, fully reliably, determine whether <> refers to a template, but I don't know for sure. > Another related question: although there is no maximum bound on how far > apart template/generic brackets can be, I believe that in practice, they > are never that far apart (a few hundred bytes max, perhaps). Is this, in > fact, the case? A few hundred characters is probably a little too small, but in practice I think one thousand characters is probably usually sufficient. Ian