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

sami wagiaalla swagiaal@redhat.com
Fri Oct 8 19:05:00 GMT 2010


> Sami>  A fix for this bug http://sourceware.org/bugzilla/show_bug.cgi?id=10343
> Sami>  This patch makes it a little bit cheaper to convert a pointer to void*
> Sami>  than any other pointer conversion.
>

This is a better patch. One problem with the rank function is that it 
assumed that the conversion 'badness' of converting an int* to a char* 
is the same as the badness of converting int to char, which is not 
correct. A conversion of int* to char* is just not allowed. This patch 
corrects that.

This patch also introduces BASE_PTR_CONVERSION_BADNESS. In the C++ spec 
this is not its own type of conversion. It is said to fall under pointer 
conversion and have the same rank, but the spec later specifies that a 
conversion of a pointer to a pointer to one of its bases is is preferred 
to a conversion of that pointer to a void* as you have specified in the 
following example. So, I decided to just make it its own rank.

> Consider this test:
>
>      struct B { };
>      struct D : public B { };
>      void f (void *x) { }
>      void f (B *x) { }
>      void g(D *x) { f(x); }
>
> This should call f(B*), but with your patch I suspect it will call
> f(void*).
>

This is correctly handled but the current patch, and tested by oranking.exp.

This patch series was regression tested on x8664 with gcc-4.4.4-f13

Thanks,
   Sami
-------------- next part --------------
A non-text attachment was scrubbed...
Name: overload_voidp.patch
Type: text/x-patch
Size: 12083 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20101008/cb12c21d/attachment.bin>


More information about the Gdb-patches mailing list