www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15306] New: Delegates with shared context

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

          Issue ID: 15306
           Summary: Delegates with shared context
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: jakobovrum gmail.com

void main()
{
    int i = 42;

    // Correctly prevented for immutable context
    // auto dg = delegate void() immutable { auto inner = i; };

    // Incorrectly allowed; context has unshared aliasing
    int* p = &i;
    auto dg = delegate int() shared { return *p; };
    assert(dg() == i);
}

---

Also, there doesn't appear to be any inference of the context type qualifier,
neither for function literals nor nested functions. Taking the address of a
member function of an immutable/shared object doesn't seem to give the context
type qualifier either.

--
Nov 09 2015