From: Yao Qi <yao@codesourcery.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH 1/4] testcase - pointer to member function
Date: Thu, 22 Nov 2012 07:32:00 -0000 [thread overview]
Message-ID: <1353569539-744-2-git-send-email-yao@codesourcery.com> (raw)
In-Reply-To: <1353569539-744-1-git-send-email-yao@codesourcery.com>
Hi,
The new test cases expose some problem in GDB on handling member
pointers, and there are two fails shown below on current GDB trunk.
print (diamond.*diamond_pfunc_ptr) (20)^M
Non-pointer-to-member value used in pointer-to-member construct^M
FAIL: gdb.cp/member-ptr.exp: print (diamond.*diamond_pfunc_ptr)(20)
ptype (a.*pmf)(3)^M
type = int (A * const, int)^M
FAIL: gdb.cp/member-ptr.exp: ptype (a.*pmf)(3)
The following patches will fix them.
gdb/testsuite:
2012-11-22 Daniel Jacobowitz <dan@codesourcery.com>
* gdb.cp/member-ptr.cc (class Diamond): Add func_ptr.
(func): New function.
(main): Initialize diamond.func_ptr and add diamond_pfunc_ptr.
* gdb.cp/member-ptr.exp: Add new tests for ptype and for
pointers to members with pointer-to-function type.
---
gdb/testsuite/gdb.cp/member-ptr.cc | 17 +++++++++++++++++
gdb/testsuite/gdb.cp/member-ptr.exp | 28 ++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/gdb/testsuite/gdb.cp/member-ptr.cc b/gdb/testsuite/gdb.cp/member-ptr.cc
index 17f022c..6cb87ef 100644
--- a/gdb/testsuite/gdb.cp/member-ptr.cc
+++ b/gdb/testsuite/gdb.cp/member-ptr.cc
@@ -137,6 +137,7 @@ class Diamond : public Padding, public Left, public Right
{
public:
virtual int vget_base ();
+ int (*func_ptr) (int);
};
int Diamond::vget_base ()
@@ -144,6 +145,12 @@ int Diamond::vget_base ()
return this->Left::x + 2000;
}
+int
+func (int x)
+{
+ return 19 + x;
+}
+
int main ()
{
A a;
@@ -161,6 +168,7 @@ int main ()
int (Diamond::*right_vpmf) ();
int (Base::*base_vpmf) ();
int Diamond::*diamond_pmi;
+ int (* Diamond::*diamond_pfunc_ptr) (int);
PMI null_pmi;
PMF null_pmf;
@@ -178,6 +186,7 @@ int main ()
diamond.Left::x = 77;
diamond.Right::x = 88;
+ diamond.func_ptr = func;
/* Some valid pointer to members from a base class. */
left_pmf = (int (Diamond::*) ()) (int (Left::*) ()) (&Base::get_x);
@@ -192,11 +201,19 @@ int main ()
/* A pointer to data member from a base class. */
diamond_pmi = (int Diamond::*) (int Left::*) &Base::x;
+ /* A pointer to data member, where the member is itself a pointer to
+ a function. */
+ diamond_pfunc_ptr = (int (* Diamond::*) (int)) &Diamond::func_ptr;
+
null_pmi = NULL;
null_pmf = NULL;
pmi = NULL; /* Breakpoint 1 here. */
+ // Invalid (uses diamond_pfunc_ptr as a function):
+ // diamond.*diamond_pfunc_ptr (20);
+ (diamond.*diamond_pfunc_ptr) (20);
+
k = (a.*pmf)(3);
pmi = &A::jj;
diff --git a/gdb/testsuite/gdb.cp/member-ptr.exp b/gdb/testsuite/gdb.cp/member-ptr.exp
index f569ca9..ae2b8b4 100644
--- a/gdb/testsuite/gdb.cp/member-ptr.exp
+++ b/gdb/testsuite/gdb.cp/member-ptr.exp
@@ -376,6 +376,33 @@ gdb_test_multiple "print ((int) pmi) == ((char *) &a.j - (char *) & a)" $name {
}
}
+# Check pointers to data members, which are themselves pointers to
+# functions. These behave like data members, not like pointers to
+# member functions.
+
+gdb_test "ptype diamond_pfunc_ptr" \
+ "type = int \\(\\*Diamond::\\*\\)\\(int\\)"
+
+gdb_test "ptype diamond.*diamond_pfunc_ptr" \
+ "type = int \\(\\*\\)\\(int\\)"
+
+# This one is invalid; () binds more tightly than .*, so it tries to
+# call the member pointer as a normal pointer-to-function.
+
+gdb_test "print diamond.*diamond_pfunc_ptr (20)" \
+ "Invalid data type for function to be called."
+
+# With parentheses, it is valid.
+
+gdb_test "print (diamond.*diamond_pfunc_ptr) (20)" \
+ "$vhn = 39"
+
+# Make sure that we do not interpret this as either a member pointer
+# call or a member function call.
+
+gdb_test "print diamond.func_ptr (20)" \
+ "$vhn = 39"
+
# ==========================
# pointer to member function
# ==========================
@@ -595,6 +622,7 @@ gdb_test_multiple "print (a.*pmf)(3)" $name {
}
gdb_test "ptype a.*pmf" "type = int \\(A \\*( const)?, int\\)"
+gdb_test "ptype (a.*pmf)(3)" "type = int"
# Print out a pointer to data member which requires looking into
# a base class.
--
1.7.7.6
next prev parent reply other threads:[~2012-11-22 7:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-22 7:32 [PATCH 0/4] Fix member pointer bugs Yao Qi
2012-11-22 7:32 ` Yao Qi [this message]
2012-11-26 16:32 ` [PATCH 1/4] testcase - pointer to member function Tom Tromey
2012-11-22 7:33 ` [PATCH 2/4] factor code Yao Qi
2012-11-22 7:33 ` [PATCH 4/4] Handle TYPE_CODE_MEMBERPTR Yao Qi
2012-11-22 8:07 ` Yao Qi
2012-11-26 16:42 ` Tom Tromey
2012-11-22 7:33 ` [PATCH 3/4] Use TYPE_TARGET_TYPE Yao Qi
2012-11-26 16:41 ` Tom Tromey
2012-11-27 8:03 ` [committed]: [PATCH 0/4] Fix member pointer bugs Yao Qi
2012-11-28 14:47 ` Tom Tromey
2012-11-28 15:14 ` Yao Qi
2012-11-28 16:37 ` Tom Tromey
2012-11-29 7:46 ` Yao Qi
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=1353569539-744-2-git-send-email-yao@codesourcery.com \
--to=yao@codesourcery.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