This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] handling of 'operator' in cp_find_first_component



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):


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 at 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 at 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.


--Dan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]