digitalmars.D.learn - null matches typed pointers before void pointers
- Andrej Mitrovic (10/10) May 24 2012 I'm not sure if this is a bug or not:
- Justin Whear (8/22) May 24 2012 Perhaps it should be ambiguous due to the special nature of null, but I
- bearophile (4/6) May 24 2012 Maybe a compile-time error is better here.
- bearophile (1/2) May 24 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8146
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?
May 24 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
May 24 2012
Justin Whear:Perhaps it should be ambiguous due to the special nature of null,Maybe a compile-time error is better here. Bye, bearophile
May 24 2012
Maybe a compile-time error is better here.http://d.puremagic.com/issues/show_bug.cgi?id=8146
May 24 2012