* RFC: fix PR c++/15116
@ 2013-02-21 19:30 Tom Tromey
2013-02-21 19:34 ` Tom Tromey
2013-03-15 17:32 ` Tom Tromey
0 siblings, 2 replies; 3+ messages in thread
From: Tom Tromey @ 2013-02-21 19:30 UTC (permalink / raw)
To: gdb-patches
This fixes PR c++/15116.
The bug is that overloading doesn't work if one of the arguments has
function type.
I fixed this by updating types_equal to account for this situation.
This allows rank_one_type to work properly.
A couple notes on this.
First, types_equal is fairly primitive.
There is a fuller deep-comparison approach in py-type.c.
However, that may be overkill here -- and actually seems like it could
break overload resolution (see the gross integer_types_same_name_p).
Second, overload resolution can actually do a kind of second overload
resolution, according to the standard. This is well-formed:
int f(int x) { return x; }
double f(double x) { return x; }
int overload(int x, int (*f)(int)) { return f(x); }
int main()
{
return overload(0, f);
}
... and here we would have to do overload resolution on the argument
'f'.
I will file a separate bug for this.
Built and regtested on x86-64 Fedora 16.
New test case included.
Tom
PR c++/15116:
* gdbtypes.c (types_equal): Handle TYPE_CODE_FUNC.
* gdb.cp/overload.cc (intintfunc): New.
* gdb.cp/overload.exp: Add regression test.
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 12730d7..a1c4018 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2456,6 +2456,25 @@ types_equal (struct type *a, struct type *b)
if (a == b)
return 1;
+ /* Two function types are equal if their argument and return types
+ are equal. */
+ if (TYPE_CODE (a) == TYPE_CODE_FUNC)
+ {
+ int i;
+
+ if (TYPE_NFIELDS (a) != TYPE_NFIELDS (b))
+ return 0;
+
+ if (!types_equal (TYPE_TARGET_TYPE (a), TYPE_TARGET_TYPE (b)))
+ return 0;
+
+ for (i = 0; i < TYPE_NFIELDS (a); ++i)
+ if (!types_equal (TYPE_FIELD_TYPE (a, i), TYPE_FIELD_TYPE (b, i)))
+ return 0;
+
+ return 1;
+ }
+
return 0;
}
diff --git a/gdb/testsuite/gdb.cp/overload.cc b/gdb/testsuite/gdb.cp/overload.cc
index ba0678f..5c782a4 100644
--- a/gdb/testsuite/gdb.cp/overload.cc
+++ b/gdb/testsuite/gdb.cp/overload.cc
@@ -97,6 +97,8 @@ class D: C {};
int bar (A) { return 11; }
int bar (B) { return 22; }
+int intintfunc (int x) { return x; }
+
int main ()
{
char arg2 = 2;
diff --git a/gdb/testsuite/gdb.cp/overload.exp b/gdb/testsuite/gdb.cp/overload.exp
index 3ebc642..9d49516 100644
--- a/gdb/testsuite/gdb.cp/overload.exp
+++ b/gdb/testsuite/gdb.cp/overload.exp
@@ -139,6 +139,9 @@ gdb_test "print foo_instance3" "\\$\[0-9\]+ = \{ifoo = 222, ccpfoo = $hex \"A\"\
gdb_test "print foo_instance1.overloadargs(1)" "\\$\[0-9\]+ = 1" \
"print call overloaded func 1 arg"
+# Regression test for overloading with function pointer type.
+gdb_test "print foo_instance1.overloadfnarg(23, intintfunc)" " = 23"
+
# If GDB fails to restore the selected frame properly after the
# inferior function call above (see GDB PR 1155 for an explanation of
# why this might happen), all the subsequent tests will fail. We
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: RFC: fix PR c++/15116
2013-02-21 19:30 RFC: fix PR c++/15116 Tom Tromey
@ 2013-02-21 19:34 ` Tom Tromey
2013-03-15 17:32 ` Tom Tromey
1 sibling, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2013-02-21 19:34 UTC (permalink / raw)
To: gdb-patches
>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:
Tom> Second, overload resolution can actually do a kind of second overload
Tom> resolution, according to the standard. This is well-formed:
Tom> int f(int x) { return x; }
Tom> double f(double x) { return x; }
A minor note. It turns out that the example as written actually does
work. This is because the correct "f" appears first in the CU.
If you swap these two lines, you can make it fail:
(gdb) p overload(0,f)
Cannot resolve function overload to any overloaded instance
I've pointed this out in the PR I'm filing.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: RFC: fix PR c++/15116
2013-02-21 19:30 RFC: fix PR c++/15116 Tom Tromey
2013-02-21 19:34 ` Tom Tromey
@ 2013-03-15 17:32 ` Tom Tromey
1 sibling, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2013-03-15 17:32 UTC (permalink / raw)
To: gdb-patches
>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:
Tom> This fixes PR c++/15116.
Tom> The bug is that overloading doesn't work if one of the arguments has
Tom> function type.
I'm checking this in now.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-03-15 17:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-21 19:30 RFC: fix PR c++/15116 Tom Tromey
2013-02-21 19:34 ` Tom Tromey
2013-03-15 17:32 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox