Thread overview
[Issue 10083] New: Insufficient IFTI/eponymous template specification
May 14, 2013
timon.gehr@gmx.ch
May 23, 2013
Kenji Hara
Jun 27, 2013
Walter Bright
May 14, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10083

           Summary: Insufficient IFTI/eponymous template specification
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: timon.gehr@gmx.ch


--- Comment #0 from timon.gehr@gmx.ch 2013-05-14 12:01:58 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 23, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10083


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2013-05-22 22:21:53 PDT ---
https://github.com/D-Programming-Language/dmd/pull/2041

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 27, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10083



--- Comment #2 from github-bugzilla@puremagic.com 2013-06-26 22:17:15 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 27, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10083


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------