From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24607 invoked by alias); 22 Apr 2003 15:23:58 -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 24600 invoked from network); 22 Apr 2003 15:23:57 -0000 Received: from unknown (HELO crack.them.org) (65.125.64.184) by sources.redhat.com with SMTP; 22 Apr 2003 15:23:57 -0000 Received: from nevyn.them.org ([66.93.61.169] ident=mail) by crack.them.org with asmtp (Exim 3.12 #1 (Debian)) id 197zci-0004YF-00; Tue, 22 Apr 2003 10:23:56 -0500 Received: from drow by nevyn.them.org with local (Exim 3.36 #1 (Debian)) id 197zcS-0004WE-00; Tue, 22 Apr 2003 11:23:40 -0400 Date: Tue, 22 Apr 2003 15:23:00 -0000 From: Daniel Jacobowitz To: Daniel Berlin Cc: David Carlton , gdb-patches@sources.redhat.com Subject: Re: [RFA] handling of 'operator' in cp_find_first_component Message-ID: <20030422152340.GA17043@nevyn.them.org> Mail-Followup-To: Daniel Berlin , David Carlton , gdb-patches@sources.redhat.com References: <20030422032152.GA5033@nevyn.them.org> <5431A3D8-74CF-11D7-A78B-000A95A34564@dberlin.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5431A3D8-74CF-11D7-A78B-000A95A34564@dberlin.org> User-Agent: Mutt/1.5.1i X-SW-Source: 2003-04/txt/msg00398.txt.bz2 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) > >and > > long foo (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 int foo(T); template 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)" and the other would be "long foo (int)". > template blah foo (int a) > { > return a; > } > int main(void) > { > int q = foo(5); > long r = foo(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) > 00000000 W long foo(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) returning int and a foo(int) returning long. Note that they have unique names because one's foo(int) and the other's foo(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)" and "long foo(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