[Issue 1983] Delegates violate const

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Nov 29 19:18:57 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=1983

--- Comment #21 from anonymous4 <dfj1esp02 at sneakemail.com> ---
Nice progress. New test case:
---
struct A
{
    void delegate() a;
    int b;
    void f(){ a=&g; }
    void g(){ b++; }
    int h() const { a(); return b; }
}

void f(ref const A a)
{
    const int b1=a.h, b2=a.h;
    assert(b1==b2,"changed");
}

unittest
{
    A a;
    a.f();
    f(a);
}
---

Though issue 16058 allows one to design API that enforces correctness:

void f(void delegate() const a);
unittest
{
    A a;
    f(&a.g);
}
Error: cannot pass argument &a.g of type void delegate() to parameter void
delegate() const a

--


More information about the Digitalmars-d-bugs mailing list