public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@google.com>
To: Alan Mackenzie <acm@muc.de>
Cc: gcc@gcc.gnu.org
Subject: Re: Help requested on C++ template syntax (for Emacs development).
Date: Tue, 10 Jun 2008 19:05:00 -0000	[thread overview]
Message-ID: <m3ve0hglfz.fsf@google.com> (raw)
In-Reply-To: <m3zlptglv9.fsf@google.com> (Ian Lance Taylor's message of "Tue\, 10 Jun 2008 11\:56\:10 -0700")

Ian Lance Taylor <iant@google.com> writes:

> Alan Mackenzie <acm@muc.de> 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<b, c> 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 <int a1, int a2> 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.

Oh, wait, I forgot about constructors.  This is valid C++ code:

template <int a1, int a2> class a;

const int b = 1;
const int c = 2;
int d;
int e;

class foo
{
  foo (a < b, c > d);
};

extern void quux (int, int);

void bar()
{
  quux (e < b, c > d);
}

Inside the class foo, you've got a template, inside the function bar,
you've got a function call.

I think you're going to have a hard time with this.

Ian

  reply	other threads:[~2008-06-10 19:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-10 18:15 Alan Mackenzie
2008-06-10 18:56 ` Ian Lance Taylor
2008-06-10 19:05   ` Ian Lance Taylor [this message]
2008-06-15 14:12     ` Alan Mackenzie
2008-06-11 18:15 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3ve0hglfz.fsf@google.com \
    --to=iant@google.com \
    --cc=acm@muc.de \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).