From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6795 invoked by alias); 23 Apr 2003 23:27:06 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 6788 invoked from network); 23 Apr 2003 23:27:05 -0000 Received: from unknown (HELO jackfruit.Stanford.EDU) (171.64.38.136) by sources.redhat.com with SMTP; 23 Apr 2003 23:27:05 -0000 Received: (from carlton@localhost) by jackfruit.Stanford.EDU (8.11.6/8.11.6) id h3NNR3C07075; Wed, 23 Apr 2003 16:27:03 -0700 X-Authentication-Warning: jackfruit.Stanford.EDU: carlton set sender to carlton@math.stanford.edu using -f To: Daniel Berlin Cc: Daniel Jacobowitz , gdb-patches@sources.redhat.com Subject: Re: [RFA] handling of 'operator' in cp_find_first_component References: <5431A3D8-74CF-11D7-A78B-000A95A34564@dberlin.org> From: David Carlton Date: Wed, 23 Apr 2003 23:46:00 -0000 In-Reply-To: <5431A3D8-74CF-11D7-A78B-000A95A34564@dberlin.org> Message-ID: User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Common Lisp) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2003-04/txt/msg00455.txt.bz2 On Tue, 22 Apr 2003 10:33:05 -0400, Daniel Berlin 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 long foo(int a) { return 9; } template int foo (int a) { return 10; } I got: jackfruit$ g++ -c foo.cpp foo.cpp:6: new declaration `template int foo(int)' foo.cpp:2: ambiguates old declaration `template long int foo(int)' Except that I don't understand C++ as well as I could: according to , 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 int foo(int a) { return C(); } template 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