Bug 13843 – Issue when passing a delegate as an class alias template parameter
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-12-09T13:22:00Z
Last change time
2015-02-18T03:42:10Z
Keywords
link-failure, pull
Assigned to
nobody
Creator
dev
Comments
Comment #0 by dev — 2014-12-09T13:22:08Z
There is an issue when passing a delegate as an class alias template parameter to be used with std.functional.binaryFun. Look at this code:
import std.stdio;
import std.functional;
class Foo(T, alias greater = "a > b")
{
private alias compare = binaryFun!(greater);
public this()
{
writefln("%s", compare(2, 1));
}
}
void main(string[] args)
{
// These work:
auto foo1 = new Foo!(int, "a > b");
auto foo2 = new Foo!(int, (a, b) => a > b);
auto foo4 = new Foo!(int, delegate(a, b){return a > b;});
// The following works when the delegate method is called without 'this.'
// otherwise they generate linker Errors:
auto foo3 = new Foo!(int, (int a, int b) => a > b);
auto foo5 = new Foo!(int, delegate(int a, int b){return a > b;});
}
If i remove the 'this.' from the compare method call, all works fine. After that call, i can call compare *with* 'this.' and all works. But there has to be an initial call made without the 'this.' for it to work from then on.
If i leave the 'this.' in place and pass a delegate as the compare function using types in the parameter list, a linker error occurs when calling the delegate.
Comment #1 by dev — 2014-12-09T13:24:15Z
Changing the compare call to this:
writefln("%s", this.compare(2, 1));
Exhibits the linker error.