From: Tom Tromey <tromey@redhat.com>
To: gdb-patches@sourceware.org
Subject: RFC: fix PR c++/15116
Date: Thu, 21 Feb 2013 19:30:00 -0000 [thread overview]
Message-ID: <87ppztbh2x.fsf@fleche.redhat.com> (raw)
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
next reply other threads:[~2013-02-21 19:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-21 19:30 Tom Tromey [this message]
2013-02-21 19:34 ` Tom Tromey
2013-03-15 17:32 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ppztbh2x.fsf@fleche.redhat.com \
--to=tromey@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox