Bug 5041 – Cannot check functor in template constraint
Status
RESOLVED
Resolution
WORKSFORME
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-10-11T15:10:00Z
Last change time
2012-05-30T21:06:57Z
Keywords
rejects-valid
Assigned to
nobody
Creator
rsinfu
Comments
Comment #0 by rsinfu — 2010-10-11T15:10:39Z
DMD rejects accessing to a symbol of a function object passed via template alias parameter in template constraints.
--------------------
void main()
{
Fun fun;
test!fun();
}
struct Fun
{
int opCall() { return 0; }
}
void test(alias fun)()
if (is(int == typeof(fun()))) // (13)
{
fun();
}
--------------------
% dmd -o- -c test.d
test.d(13): Error: function test.test(alias fun) if (is(int == typeof(fun()))).test cannot access frame of function D main
test.d(13): Error: function test.test(alias fun) if (is(int == typeof(fun()))).test cannot access frame of function D main
test.d(13): Error: function test.test(alias fun) if (is(int == typeof(fun()))).test cannot access frame of function D main
test.d(13): Error: function test.test(alias fun) if (is(int == typeof(fun()))).test cannot access frame of function D main
--------------------
Passing functor symbols via template alias parameters should be valid like nested functions (see discussion in bug 3051), and actually, it works fine modulo the reported problem. It's a problem of template constraints.
--------------------
void main()
{
Fun fun;
test!fun();
assert(fun.value == 123); // okay, passes
}
struct Fun
{
int value;
void opCall(int a) { value = a; }
}
void test(alias fun)()
{
fun(123);
}