This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[RFA] C++ method calls
- To: gdb-patches at sourceware dot cygnus dot com
- Subject: [RFA] C++ method calls
- From: Nick Duffek <nsd at redhat dot com>
- Date: Sat, 8 Jul 2000 22:05:09 -0400
Given the following C++ code:
class A {
public:
int a;
};
class B : public A {
public:
int b;
};
B b;
class C {
int ptr (A *a) { return a->a; }
int ref (A &a) { return a.a; }
};
C c;
the following GDB commands should fail but don't:
call c.ptr (&c);
call c.ref (c);
After fixing that with part of the appended patch, the following GDB
commands shouldn't fail but do:
call c.ptr (&b);
call c.ref (b);
The patch fixes the above problems, adds gdb.c++/classes.exp tests to
check for them, and fixes a minor indentation problem. It also seems to
fix two gdb.c++/namespace.exp failures. There are no regressions on
sparc-sun-solaris2.
The enum test patch I posted earlier today needs to be applied first.
Okay to apply?
Nick Duffek
nsd@redhat.com
2000-07-08 Nick Duffek <nsd@redhat.com>
* gdbtypes.c (is_ancestor): Infer type equivalence from name
equivalence.
(rank_one_type): Use strcmp instead of == to compare type names.
Don't swap parm with arg when checking TYPE_CODE_REF types.
* valops.c (find_overload_match): Fix indentation. Compare
parameter rankings to 0..9, 10..99, and 100+ instead of 0, 10,
and 100.
Index: gdb/gdbtypes.c
===================================================================
diff -up gdb/gdbtypes.c gdb/gdbtypes.c
--- gdb/gdbtypes.c Sat Jul 8 21:25:29 2000
+++ gdb/gdbtypes.c Sat Jul 8 18:49:12 2000
@@ -1736,6 +1736,9 @@ is_ancestor (base, dclass)
if (base == dclass)
return 1;
+ if (TYPE_NAME (base) && TYPE_NAME (dclass) &&
+ !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
+ return 1;
for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
@@ -2206,7 +2209,8 @@ rank_one_type (parm, arg)
really are the same.
*/
- if (TYPE_NAME (parm) == TYPE_NAME (arg))
+ if (TYPE_NAME (parm) && TYPE_NAME (arg) &&
+ !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
return 0;
/* Check if identical after resolving typedefs */
@@ -2216,10 +2220,10 @@ rank_one_type (parm, arg)
/* See through references, since we can almost make non-references
references. */
if (TYPE_CODE (arg) == TYPE_CODE_REF)
- return (rank_one_type (TYPE_TARGET_TYPE (arg), parm)
+ return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
+ REFERENCE_CONVERSION_BADNESS);
if (TYPE_CODE (parm) == TYPE_CODE_REF)
- return (rank_one_type (arg, TYPE_TARGET_TYPE (parm))
+ return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
+ REFERENCE_CONVERSION_BADNESS);
if (overload_debug)
/* Debugging only. */
Index: gdb/valops.c
===================================================================
diff -up gdb/valops.c gdb/valops.c
--- gdb/valops.c Sat Jul 8 21:25:37 2000
+++ gdb/valops.c Sat Jul 8 21:25:11 2000
@@ -2858,16 +2858,16 @@ find_overload_match (arg_types, nargs, n
break;
}
free (parm_types);
-if (overload_debug)
-{
- if (method)
- fprintf_filtered (gdb_stderr,"Overloaded method instance %s, # of parms %d\n", fns_ptr[ix].physname, nparms);
- else
- fprintf_filtered (gdb_stderr,"Overloaded function instance %s # of parms %d\n", SYMBOL_DEMANGLED_NAME (oload_syms[ix]), nparms);
- for (jj = 0; jj < nargs; jj++)
- fprintf_filtered (gdb_stderr,"...Badness @ %d : %d\n", jj, bv->rank[jj]);
- fprintf_filtered (gdb_stderr,"Overload resolution champion is %d, ambiguous? %d\n", oload_champ, oload_ambiguous);
-}
+ if (overload_debug)
+ {
+ if (method)
+ fprintf_filtered (gdb_stderr,"Overloaded method instance %s, # of parms %d\n", fns_ptr[ix].physname, nparms);
+ else
+ fprintf_filtered (gdb_stderr,"Overloaded function instance %s # of parms %d\n", SYMBOL_DEMANGLED_NAME (oload_syms[ix]), nparms);
+ for (jj = 0; jj < nargs; jj++)
+ fprintf_filtered (gdb_stderr,"...Badness @ %d : %d\n", jj, bv->rank[jj]);
+ fprintf_filtered (gdb_stderr,"Overload resolution champion is %d, ambiguous? %d\n", oload_champ, oload_ambiguous);
+ }
} /* end loop over all candidates */
/* NOTE: dan/2000-03-10: Seems to be a better idea to just pick one
if they have the exact same goodness. This is because there is no
@@ -2890,15 +2890,11 @@ if (overload_debug)
/* Check how bad the best match is */
for (ix = 1; ix <= nargs; ix++)
{
- switch (oload_champ_bv->rank[ix])
- {
- case 10:
- oload_non_standard = 1; /* non-standard type conversions needed */
- break;
- case 100:
- oload_incompatible = 1; /* truly mismatched types */
- break;
- }
+ if (oload_champ_bv->rank[ix] >= 100)
+ oload_incompatible = 1; /* truly mismatched types */
+
+ else if (oload_champ_bv->rank[ix] >= 10)
+ oload_non_standard = 1; /* non-standard type conversions needed */
}
if (oload_incompatible)
{