Bug 10083 – Insufficient IFTI/eponymous template specification

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-14T12:01:00Z
Last change time
2014-09-14T13:18:33Z
Keywords
pull
Assigned to
nobody
Creator
timon.gehr

Comments

Comment #0 by timon.gehr — 2013-05-14T12:01:58Z
The spec does not say how IFTI and the eponymous template trick behave when the eponymous declaration is overloaded. DMD's strategy is roughly: use the first eponymous declaration that can be found without analysing the template body for IFTI, then use the first eponymous declaration in the analyzed template body to resolve the eponymous declaration after instantiation. --- import std.stdio; template fun(T){ int fun(double arg){ return 1; } int fun(T arg){ return 0; } } void main(){ writeln(fun(2)); } // error --- import std.stdio; template fun(T){ int fun(T arg){ return 0; } int fun(double arg){ return 1; } } void main(){ writeln(fun(2)); } // ok --- This has funny implications, as the compiler may decide to resolve to a different declaration than was used for IFTI later, without doing any kind of overload resolution within the template body. --- template fun(T){ int fun(T arg){ return 0; } static if(true) int fun(double arg){ return 1; } } pragma(msg, fun(2)); // 0 --- template fun(T){ static if(true) int fun(double arg){ return 1; } int fun(T arg){ return 0; } } pragma(msg, fun(2)); // 1 --- In the second case, instantiation is performed with the second function, so T is resolved to 'int', but in the end, the 'double' overload is called with an implicit conversion.
Comment #1 by k.hara.pg — 2013-05-22T22:21:53Z
Comment #2 by github-bugzilla — 2013-06-26T22:17:15Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/10cf2d97cd8fffce312d8bf48ca4830ceb5bed05 fix Issue 10083 - Insufficient IFTI/eponymous template specification https://github.com/D-Programming-Language/dmd/commit/ed83e21e69bce7dc4b7ef223c6e0cfb59013bf82 Merge pull request #2041 from 9rnsr/fix10083 Issue 10083 - Insufficient IFTI/eponymous template specification
Comment #3 by k.hara.pg — 2014-09-14T13:18:33Z
*** Issue 8325 has been marked as a duplicate of this issue. ***