D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 13843 - Issue when passing a delegate as an class alias template parameter
Summary: Issue when passing a delegate as an class alias template parameter
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: link-failure, pull
Depends on:
Blocks:
 
Reported: 2014-12-09 13:22 UTC by Gary Willoughby
Modified: 2015-02-18 03:42 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Gary Willoughby 2014-12-09 13:22:08 UTC
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 Gary Willoughby 2014-12-09 13:24:15 UTC
Changing the compare call to this:

	writefln("%s", this.compare(2, 1));

Exhibits the linker error.
Comment 3 github-bugzilla 2015-01-11 05:01:19 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/f3556d65281bf7383a36759e7153f5accd645b32
fix Issue 13843 - Issue when passing a delegate as an class alias template parameter

https://github.com/D-Programming-Language/dmd/commit/93986fd3ff4e43fa3dc06495095c4e8eccb15eea
Merge pull request #4267 from 9rnsr/fix13843

Issue 13843 - Issue when passing a delegate as an class alias template parameter
Comment 4 github-bugzilla 2015-02-18 03:42:10 UTC
Commits pushed to 2.067 at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/f3556d65281bf7383a36759e7153f5accd645b32
fix Issue 13843 - Issue when passing a delegate as an class alias template parameter

https://github.com/D-Programming-Language/dmd/commit/93986fd3ff4e43fa3dc06495095c4e8eccb15eea
Merge pull request #4267 from 9rnsr/fix13843