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.
Comment #1 by jakobovrum — 2015-11-09T12:12:53Z
(In reply to Jakob Ovrum from comment #0)
> 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.
Comment #2 by dfj1esp02 — 2015-11-10T11:51:36Z
Looks like quite non-trivial feature and delegates don't provide much type safety anyway.