D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15043 - a temporary is needed when trying to set a delegate using __traits(getOverloads)
Summary: a temporary is needed when trying to set a delegate using __traits(getOverloads)
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2015-09-11 21:00 UTC by basile-z
Modified: 2019-01-02 16:27 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description basile-z 2015-09-11 21:00:28 UTC
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 basile-z 2015-09-11 22:58:28 UTC
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 basile-z 2015-09-12 19:58:07 UTC
he knows the topic.
Comment 3 ag0aep6g 2016-04-11 20:42:09 UTC
The bug is still there. ICEs are certainly not WONTFIX. Reopening.
Comment 4 basile-z 2018-01-13 19:37:01 UTC
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(){}
Comment 5 basile-z 2019-01-02 16:27:55 UTC
__traits dont give expressions