From: David Carlton <carlton@math.stanford.edu>
To: Daniel Berlin <dberlin@dberlin.org>
Cc: Daniel Jacobowitz <drow@mvista.com>, gdb-patches@sources.redhat.com
Subject: Re: [RFA] handling of 'operator' in cp_find_first_component
Date: Wed, 23 Apr 2003 23:46:00 -0000 [thread overview]
Message-ID: <ro1znmgeqwo.fsf@jackfruit.Stanford.EDU> (raw)
In-Reply-To: <5431A3D8-74CF-11D7-A78B-000A95A34564@dberlin.org>
On Tue, 22 Apr 2003 10:33:05 -0400, Daniel Berlin <dberlin@dberlin.org> said:
> 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;
> }
Yeah, but that's illegal, isn't it? You can't have two functions that
differ only in return type: otherwise, how would the compiler know
which one to use in a call to foo?
I tried it out in GCC; the above doesn't compile (I guess templates
with 0 parameters aren't legal), but when I compiled the following
file:
template <typename T> long foo(int a)
{
return 9;
}
template <typename T> int foo (int a)
{
return 10;
}
I got:
jackfruit$ g++ -c foo.cpp
foo.cpp:6: new declaration `template<class T> int foo(int)'
foo.cpp:2: ambiguates old declaration `template<class T> long int foo(int)'
Except that I don't understand C++ as well as I could: according to
<http://gcc.gnu.org/ml/gcc-patches/2000-02/msg00879.html>, there are
cases involving templated functions where the compiler is allowed to
disambiguate based on return type. The above isn't one of them, and
even if I modify them to return objects of completely different types,
I still get a similar error message.
Hmm. I'm confused. When I play around with this further, life is
getting more bizarre: GCC happily compiles the following:
class C {};
template <typename T> int foo(int a)
{
return C();
}
template <typename T> T foo (T a)
{
return 10;
}
even though the first function is returning an object of the wrong
type! Am I going crazy, or is that just a bug? The first function
sure doesn't compile if I remove the template part.
At any rate, obviously I should try to read the standard or Stroustrup
to understand this better.
David Carlton
carlton@math.stanford.edu
next prev parent reply other threads:[~2003-04-23 23:27 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
2003-04-23 23:46 ` David Carlton [this message]
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=ro1znmgeqwo.fsf@jackfruit.Stanford.EDU \
--to=carlton@math.stanford.edu \
--cc=dberlin@dberlin.org \
--cc=drow@mvista.com \
--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