null matches typed pointers before void pointers

Justin Whear justin at economicmodeling.com
Thu May 24 08:24:29 PDT 2012


On Thu, 24 May 2012 14:50:38 +0200, Andrej Mitrovic wrote:

> I'm not sure if this is a bug or not:
> 
> struct Foo { }
> 
> void test(void* test) { assert(0); }
> void test(Foo* test)  { }
> 
> void main()
> {
>     test(null);
> }
> 
> The call matches the second overload: "void test(Foo* test)". But
> shouldn't this be an ambiguous call?

Perhaps it should be ambiguous due to the special nature of null, but I 
think I understand why dmd isn't treating it as such. Firstly, null got 
promoted to its own type (is(typeof(null) != void*)) a few releases ago 
so it won't exactly match on the void* overload. Secondly, the Foo* 
overload is more specific (any Foo* can implicitly convert to a void*) so 
the overload picker goes with it.

Justin


More information about the Digitalmars-d-learn mailing list