Bug 15043 – a temporary is needed when trying to set a delegate using __traits(getOverloads)
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-09-11T21:00:28Z
Last change time
2019-01-02T16:27:55Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Basile-z
Comments
Comment #0 by b2.temp — 2015-09-11T21:00:28Z
the following program compiled without any particular switch
---
class Foo
{
uint bar(){return 0;}
this()
{
foreach(member; __traits(allMembers, typeof(this)))
foreach(overload; __traits(getOverloads, typeof(this), member))
static if (member == "bar")
setDg(&overload);
}
void setDg(uint delegate() dg){}
}
void main(){}
---
crashes DMD and outputs:
> Error: delegates are only for non-static functions
> Assertion failure: '(int)vindex >= 0' on line 3439 in file 'e2ir.c'
- The bug looks highly related to https://issues.dlang.org/show_bug.cgi?id=13920.
- The bug only produces a messages since 2.068, previously it was only crashing without any helpful dignostic message.
Comment #1 by b2.temp — 2015-09-11T22:58:28Z
Lowered importance. Actually the problem seems to come from a lValue/rValue thing because when using an intermediate variable to carry the delegate then this works:
---
static if (member == "bar")
{
auto dg = &overload; // OK with intermediate value
setDg(dg);
}
---
Comment #2 by b2.temp — 2015-09-12T19:58:07Z
he knows the topic.
Comment #3 by ag0aep6g — 2016-04-11T20:42:09Z
The bug is still there. ICEs are certainly not WONTFIX. Reopening.
Comment #4 by b2.temp — 2018-01-13T19:37:01Z
The code now leads to a wrong diagnostic
"/tmp/temp_7FECD0F3D050.d(9,27): Error: delegates are only for non-static functions"
but on the other hand this works
class Foo
{
uint bar(){return 0;}
this()
{
foreach(member; __traits(allMembers, typeof(this)))
foreach(overload; __traits(getOverloads, typeof(this), member))
static if (member == "bar")
{uint delegate() a = &overload; setDg(a);}
}
void setDg(uint delegate() dg){}
}
void main(){}