From: Daniel Jacobowitz <drow@mvista.com>
To: Daniel Berlin <dberlin@dberlin.org>
Cc: David Carlton <carlton@bactrian.org>, gdb-patches@sources.redhat.com
Subject: Re: [RFA] handling of 'operator' in cp_find_first_component
Date: Tue, 22 Apr 2003 15:23:00 -0000 [thread overview]
Message-ID: <20030422152340.GA17043@nevyn.them.org> (raw)
In-Reply-To: <5431A3D8-74CF-11D7-A78B-000A95A34564@dberlin.org>
On Tue, Apr 22, 2003 at 10:33:05AM -0400, Daniel Berlin wrote:
>
> On Monday, April 21, 2003, at 11:21 PM, Daniel Jacobowitz wrote:
>
> >
> >i.e. you can't have a program with
> > int foo<int> (int)
> >and
> > long foo<int> (int)
> >in it!
>
>
> Stop right here.
>
> This is not quite right, since the second example is invalid.
> You can, however, have (geez i haven't written C++ templates in a
> while. it took me a few compiles to get this right):
I don't think it's invalid on its own. I think I'm just not being
clear. It's something like:
template <typename T> int foo(T);
template <typename T> long foo(T);
template <> int foo (int) { return 1;}
template <> long foo (int) { return 2;}
Not that that's valid, but one of them would be "int foo<int> (int)"
and the other would be "long foo<int> (int)".
> template <class blah> blah foo (int a)
> {
> return a;
> }
> int main(void)
> {
> int q = foo<int>(5);
> long r = foo<long>(5);
> }
>
> Note the only real difference here is in return type.
> It also definitely generates two functions:
> root@dberlin root]# nm -C a.o
> U __gxx_personality_v0
> 00000000 T main
> 00000000 W int foo<int>(int)
> 00000000 W long foo<long>(int)
> [root@dberlin root]#
>
> There is no way to write exactly what you want in valid C++ (IIRC), so
> i'm not sure if this program demonstrates what you think can't be done
> or not.
>
> To answer whether you need the return type, let's add two
> specializations here and make it worse:
> template <> long foo (int a)
> {
> return 9;
> }
> template <> int foo (int a)
> {
> return 10;
> }
>
> Now, without the return type in the template, you would *never* know
> which function to call from a debugger if someone does p foo(5)
> (However, i'll note the only case you will know is when someone does
> something like p a=foo(5), where "a" is a program variable of type int
> or long).
> With the return type, you could at least present a useful list to the
> user and ask.
> Unless you want the list to have to re-demangle names so it can get the
> return type out again, or something ugly like that.
Sure we can. We look through our list of functions whose name is foo.
We find that there's a foo<int>(int) returning int and a foo<long>(int)
returning long. Note that they have unique names because one's
foo<int>(int) and the other's foo<long>(int). We then ask the user
which one he wanted.
That's what I'm suggesting; I'm just not sure if there's a valid way to
get both "int foo<int>(int)" and "long foo<int>(int)" into the same
program.
In the light of the morning, maybe it's not such a good idea after all.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
next prev parent reply other threads:[~2003-04-22 15:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-04-18 19:17 David Carlton
2003-04-18 19:47 ` Daniel Berlin
2003-04-22 3:21 ` Daniel Jacobowitz
2003-04-22 15:09 ` Daniel Berlin
2003-04-22 15:23 ` Daniel Jacobowitz [this message]
2003-04-23 23:46 ` David Carlton
2003-04-23 23:49 ` David Carlton
2003-04-24 1:13 ` Daniel Berlin
2003-04-23 23:45 ` David Carlton
2003-04-24 1:25 ` David Carlton
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=20030422152340.GA17043@nevyn.them.org \
--to=drow@mvista.com \
--cc=carlton@bactrian.org \
--cc=dberlin@dberlin.org \
--cc=gdb-patches@sources.redhat.com \
/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