digitalmars.D.bugs - [Issue 8146] New: Potentially ambiguous overloaded call
- d-bugmail puremagic.com (30/30) May 24 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8146
- d-bugmail puremagic.com (23/43) May 24 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8146
- d-bugmail puremagic.com (13/14) May 25 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8146
http://d.puremagic.com/issues/show_bug.cgi?id=8146
Summary: Potentially ambiguous overloaded call
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody puremagic.com
ReportedBy: bearophile_hugs eml.cc
This is just a potential enhancement request. It's not an enhancement request
because I am not sure about it.
A thread started by Andrej Mitrovic on D.learn:
http://forum.dlang.org/thread/mailman.1043.1337863952.24740.digitalmars-d-learn puremagic.com
In dmd 2.060alpha this code compiles and doesn't assert at run-time, so it
calls the second overload:
struct Foo {}
void test(void* test) { assert(0); }
void test(Foo* test) {}
void main() {
test(null);
}
As Andrej comments, shouldn't this be considered an ambiguous call, and refused
at compile time?
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 24 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8146
This is just a potential enhancement request. It's not an enhancement request
because I am not sure about it.
A thread started by Andrej Mitrovic on D.learn:
http://forum.dlang.org/thread/mailman.1043.1337863952.24740.digitalmars-d-learn puremagic.com
In dmd 2.060alpha this code compiles and doesn't assert at run-time, so it
calls the second overload:
struct Foo {}
void test(void* test) { assert(0); }
void test(Foo* test) {}
void main() {
test(null);
}
As Andrej comments, shouldn't this be considered an ambiguous call, and refused
at compile time?
I think, no.
First, test(Foo*) is specialized than test(void*), because Foo* is convertible
to void*, but opposite isn't.
Next, a null literal has the typeof(null) and it is *most specialized type* of
all reference types. Then typeof(null) is a specialized type than Foo*.
So, with the call 'test(null)', overload resolution will select more
specialized test(Foo*) than test(void*).
Following is a similar case by the class hierarchy.
class B{} // like void*
class C : B{} // like Foo*
class D : C{} // like typeof(null)
void foo(B o){}
void foo(C o){}
void main() {
foo(new D); // calls foo(C)
}
As far as I know, this rule is same as C++.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 24 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8146
bearophile_hugs eml.cc changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
As far as I know, this rule is same as C++.
C++ is often not not a good model to copy, but I trust your judgment and
knowledge, so I close this ER as invalid.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 25 2012









d-bugmail puremagic.com 