public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [patch] Fix overload resolution of int* vs void*
@ 2010-08-30 15:24 sami wagiaalla
  2010-08-30 16:13 ` sami wagiaalla
  2010-08-30 20:01 ` Tom Tromey
  0 siblings, 2 replies; 18+ messages in thread
From: sami wagiaalla @ 2010-08-30 15:24 UTC (permalink / raw)
  To: gdb-patches

[-- 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.

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2010-10-15 22:48 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-30 15:24 [patch] Fix overload resolution of int* vs void* sami wagiaalla
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).