From: sami wagiaalla <swagiaal@redhat.com>
To: gdb-patches@sourceware.org
Subject: [patch] Fix overload resolution of int* vs void*
Date: Mon, 30 Aug 2010 15:24:00 -0000 [thread overview]
Message-ID: <4C7BCD42.9070308@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 186 bytes --]
A fix for this bug http://sourceware.org/bugzilla/show_bug.cgi?id=10343
This patch makes it a little bit cheaper to convert a pointer to void*
than any other pointer conversion.
Sami
[-- Attachment #2: overload_voidp.patch --]
[-- Type: text/x-patch, Size: 4525 bytes --]
Fixed void* vs int* overload issue (PR C++/10343).
2010-08-30 Sami Wagiaalla <swagiaal@redhat.com>
* gdbtypes.h: Made VOID_PTR_CONVERSION_BADNESS better than
INTEGER_PROMOTION_BADNESS.
2010-08-30 Sami Wagiaalla <swagiaal@redhat.com>
PR C++/10343
* gdb.cp/overload.cc: Added test for void* vs int* overload.
* gdb.cp/overload.exp: Ditto.
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 6fc47f2..ed8d613 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1374,25 +1374,25 @@ extern int is_unique_ancestor (struct type *, struct value *);
#define INCOMPATIBLE_TYPE_BADNESS 100
/* Badness of integral promotion */
-#define INTEGER_PROMOTION_BADNESS 1
+#define INTEGER_PROMOTION_BADNESS 2
/* Badness of floating promotion */
-#define FLOAT_PROMOTION_BADNESS 1
+#define FLOAT_PROMOTION_BADNESS 2
/* Badness of integral conversion */
-#define INTEGER_CONVERSION_BADNESS 2
+#define INTEGER_CONVERSION_BADNESS 3
/* Badness of floating conversion */
-#define FLOAT_CONVERSION_BADNESS 2
+#define FLOAT_CONVERSION_BADNESS 3
/* Badness of integer<->floating conversions */
-#define INT_FLOAT_CONVERSION_BADNESS 2
+#define INT_FLOAT_CONVERSION_BADNESS 3
/* Badness of converting to a boolean */
-#define BOOLEAN_CONVERSION_BADNESS 2
+#define BOOLEAN_CONVERSION_BADNESS 3
/* Badness of pointer conversion */
-#define POINTER_CONVERSION_BADNESS 2
+#define POINTER_CONVERSION_BADNESS 3
/* Badness of conversion of pointer to void pointer */
-#define VOID_PTR_CONVERSION_BADNESS 2
+#define VOID_PTR_CONVERSION_BADNESS 1
/* Badness of converting derived to base class */
-#define BASE_CONVERSION_BADNESS 2
+#define BASE_CONVERSION_BADNESS 3
/* Badness of converting from non-reference to reference */
-#define REFERENCE_CONVERSION_BADNESS 2
+#define REFERENCE_CONVERSION_BADNESS 3
/* Non-standard conversions allowed by the debugger */
/* Converting a pointer to an int is usually OK */
diff --git a/gdb/testsuite/gdb.cp/overload.cc b/gdb/testsuite/gdb.cp/overload.cc
index 78fae14..dc117fb 100644
--- a/gdb/testsuite/gdb.cp/overload.cc
+++ b/gdb/testsuite/gdb.cp/overload.cc
@@ -24,6 +24,9 @@ int overload1arg (unsigned long);
int overload1arg (float);
int overload1arg (double);
+int overload1arg (int*);
+int overload1arg (void*);
+
int overloadfnarg (void);
int overloadfnarg (int);
int overloadfnarg (int, int (*) (int));
@@ -99,6 +102,8 @@ int main ()
unsigned long arg10 =10;
float arg11 =100.0;
double arg12 = 200.0;
+ int arg13 = 200.0;
+ char arg14 = 'a';
char *str = (char *) "A";
foo foo_instance1(111);
@@ -150,6 +155,8 @@ int foo::overload1arg (long arg) { arg = 0; return 9;}
int foo::overload1arg (unsigned long arg) { arg = 0; return 10;}
int foo::overload1arg (float arg) { arg = 0; return 11;}
int foo::overload1arg (double arg) { arg = 0; return 12;}
+int foo::overload1arg (int* arg) { arg = 0; return 13;}
+int foo::overload1arg (void* arg) { arg = 0; return 14;}
/* Test to see that we can explicitly request overloaded functions
with function pointers in the prototype. */
diff --git a/gdb/testsuite/gdb.cp/overload.exp b/gdb/testsuite/gdb.cp/overload.exp
index f05cc23..25aeb07 100644
--- a/gdb/testsuite/gdb.cp/overload.exp
+++ b/gdb/testsuite/gdb.cp/overload.exp
@@ -80,6 +80,8 @@ set re_methods "${re_methods}${ws}int overload1arg\\(long( int)?\\);"
set re_methods "${re_methods}${ws}int overload1arg\\((unsigned long|long unsigned)( int)?\\);"
set re_methods "${re_methods}${ws}int overload1arg\\(float\\);"
set re_methods "${re_methods}${ws}int overload1arg\\(double\\);"
+set re_methods "${re_methods}${ws}int overload1arg\\(int \\*\\);"
+set re_methods "${re_methods}${ws}int overload1arg\\(void \\*\\);"
set re_methods "${re_methods}${ws}int overloadfnarg\\((void|)\\);"
set re_methods "${re_methods}${ws}int overloadfnarg\\(int\\);"
set re_methods "${re_methods}${ws}int overloadfnarg\\(int, int ?\\(\\*\\) ?\\(int\\)\\);"
@@ -256,6 +258,14 @@ gdb_test "print foo_instance1.overload1arg((double)arg12)" \
"\\$\[0-9\]+ = 12" \
"print call overloaded func double arg"
+gdb_test "print foo_instance1.overload1arg(&arg13)" \
+ "\\$\[0-9\]+ = 13" \
+ "print call overloaded func int\\* arg"
+
+gdb_test "print foo_instance1.overload1arg(&arg14)" \
+ "\\$\[0-9\]+ = 14" \
+ "print call overloaded func char\\* arg"
+
# ---
# List overloaded functions.
next reply other threads:[~2010-08-30 15:24 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-30 15:24 sami wagiaalla [this message]
2010-08-30 16:13 ` sami wagiaalla
2010-08-30 20:01 ` Tom Tromey
2010-10-08 18:39 ` [patch 1/2] " sami wagiaalla
2010-10-08 18:54 ` Tom Tromey
2010-10-08 19:35 ` sami wagiaalla
2010-10-08 21:30 ` Tom Tromey
2010-10-08 19:05 ` [patch 2/2] " sami wagiaalla
2010-10-08 20:46 ` Eli Zaretskii
2010-10-08 21:10 ` sami wagiaalla
2010-10-08 22:54 ` Tom Tromey
2010-10-12 20:01 ` sami wagiaalla
2010-10-12 20:41 ` Tom Tromey
2010-10-13 15:16 ` sami wagiaalla
2010-10-13 15:49 ` Tom Tromey
2010-10-13 18:29 ` sami wagiaalla
2010-10-15 14:46 ` sami wagiaalla
2010-10-15 22:48 ` 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=4C7BCD42.9070308@redhat.com \
--to=swagiaal@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