[Issue 10083] New: Insufficient IFTI/eponymous template specification

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue May 14 12:02:00 PDT 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 at puremagic.com
        ReportedBy: timon.gehr at gmx.ch


--- Comment #0 from timon.gehr at 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: -------


More information about the Digitalmars-d-bugs mailing list