This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix overload resolution of int* vs void*


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]