Bug 12117 – Non-template overload taken when template matches better
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-02-09T04:37:00Z
Last change time
2014-02-09T23:10:12Z
Assigned to
nobody
Creator
peter.alexander.au
Comments
Comment #0 by peter.alexander.au — 2014-02-09T04:37:36Z
import std.stdio;
struct S
{
int x;
alias x this;
}
void f(T)(T t) { writeln(T.stringof); }
void f(int t) { writeln(int.stringof); }
void main()
{
f(S.init); // f(int) called
}
This writes "int", but should write "S".
The template should be preferred because it matches without implicit conversions while the non-template requires a conversion. TDPL states that the non-template should be preferred only when it matches equally well (or better) than the template.
Comment #1 by andrej.mitrovich — 2014-02-09T05:12:59Z
It likely has to do with the order of operations:
1) Try direct match of: type, then alias this, on regular function
2) Try direct match of: type, then alias this, on templated function
(I'm just speculating it works /something/ like this)
And the 'alias this' wins before a templated function is tried. I guess it's a question of priority. We'll see what Kenji and others have to say.
Comment #2 by k.hara.pg — 2014-02-09T23:10:12Z
*** This issue has been marked as a duplicate of issue 5363 ***