Bug 9990 – templates with function alias cause forward reference error
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-04-25T04:43:00Z
Last change time
2013-04-28T18:47:50Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
SebastianGraf
Comments
Comment #0 by SebastianGraf — 2013-04-25T04:43:50Z
import std.stdio;
struct S { string field; }
auto initS() { return S("hi"); }
class C(alias init)
{
private S _s;
this() { _s = init(); }
auto createProxy()
{
struct Proxy
{
private S* s;
void print() { writeln(s.field); }
}
return Proxy(&_s);
}
}
// alias SC = C!(initS);
static assert(!is(typeof(C!(initS))));
void main()
{
alias SC = C!(initS);
auto c = new SC;
c.createProxy().print();
}
This prints out "hi". If I alias SC at the global level instead, I get a compiler error:
hi.d(24): Error: template instance hi.C!(initS) forward reference of function initS
Line 24 is the line with the offending global alias. I think the global version should also compile.