diff --git a/gdb/testsuite/gdb.cp/namespace-koenig.cc b/gdb/testsuite/gdb.cp/namespace-koenig.cc index 6c2c01d..5df6a33 100644 --- a/gdb/testsuite/gdb.cp/namespace-koenig.cc +++ b/gdb/testsuite/gdb.cp/namespace-koenig.cc @@ -129,6 +129,29 @@ namespace L { } //------------ + +namespace M { + class O{ + public: + int operator== (int){ + return 18; + } + + int operator== (float){ + return 19; + } + }; + + int operator!= (O, int){ + return 20; + } + + int operator!= (O, double){ + return 21; + } + +} +//------------ int main () { @@ -180,6 +203,12 @@ main () L::A::B::O labo; foo (labo); + + M::O o; + o == 5; + o == 5.0f; + o != 5; + o != 5.0f; return first (0, c) + foo (eo) + foo (eo, eo) + foo (eo, eo, 1) + diff --git a/gdb/testsuite/gdb.cp/namespace-koenig.exp b/gdb/testsuite/gdb.cp/namespace-koenig.exp index 616b816..f9ac963 100644 --- a/gdb/testsuite/gdb.cp/namespace-koenig.exp +++ b/gdb/testsuite/gdb.cp/namespace-koenig.exp @@ -93,3 +93,10 @@ gdb_test "p bar(ko,1)" "= -1" #test lookup of objects belonging to nested namespaces gdb_test "p foo(labo)" "= 17" + +# test lookup of namespace user-defined operators +# and overload resolution. +gdb_test "p o == 5" "= 18" +gdb_test "p o == 5.0f" "= 19" +gdb_test "p o != 5" "= 20" +gdb_test "p o != 5.0f" "= 21" diff --git a/gdb/valops.c b/gdb/valops.c index e6ea6c9..25d077f 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -889,6 +889,13 @@ value_at (struct type *type, CORE_ADDR addr) return get_value_at (type, addr, 0); } +struct value * +value_at_value (struct value *value) +{ + return value_at(TYPE_TARGET_TYPE (value_type(value)), + value_as_address(value)); +} + /* Return a lazy value with type TYPE located at ADDR (cf. value_at). */ struct value * @@ -2104,6 +2111,9 @@ value_struct_elt (struct value **argp, struct value **args, struct type *t; struct value *v; + struct type **arg_types; + int nargs, i = 0; + *argp = coerce_array (*argp); t = check_typedef (value_type (*argp)); @@ -2173,6 +2183,33 @@ value_struct_elt (struct value **argp, struct value **args, *static_memfuncp = 1; } + /* try Koenig lookup. */ + if (!v && args) + { + struct symbol *symp; + /* This function, if found, will not be a member function + and does not expect a pointer as its first argument + rather the explicit structure. */ + args[0] = value_at_value(args[0]); + + nargs = 0; + if (args[1] == 0) + nargs = 1; + else if (args[2] == 0) + nargs = 2; + + arg_types = (struct type **)alloca (nargs * (sizeof (struct type *))); + /* Prepare list of argument types for overload resolution */ + for (i = 0; i < nargs; i++) + arg_types [i] = value_type (args [i]); + + find_overload_match (arg_types, nargs, name, 0 /* not method */, + 0 /* strict match */, NULL, + NULL /* pass NULL symbol since symbol is unknown */, + NULL, &symp, NULL); + + v = value_of_variable (symp, 0); + } if (!v) error (_("Structure has no component named %s."), name); return v; diff --git a/gdb/value.h b/gdb/value.h index 42b4497..1f1dead 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -348,6 +348,7 @@ extern struct value *value_from_decfloat (struct type *type, const gdb_byte *decbytes); extern struct value *value_at (struct type *type, CORE_ADDR addr); +extern struct value *value_at_value (struct value *value); extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr); extern struct value *value_from_contents_and_address (struct type *,