]>
Commit | Line | Data |
---|---|---|
b4c522fa | 1 | /* |
b4c522fa IB |
2 | TEST_OUTPUT: |
3 | --- | |
5fee5ec3 IB |
4 | fail_compilation/test15306.d(15): Error: `immutable` delegate `test15306.main.__dgliteral2` cannot access mutable data `i` |
5 | fail_compilation/test15306.d(19): Error: `shared` delegate `test15306.main.__dgliteral5` cannot access non-shared data `p` | |
b4c522fa IB |
6 | --- |
7 | */ | |
8 | ||
9 | // https://issues.dlang.org/show_bug.cgi?id=15306 | |
10 | ||
11 | void main() | |
12 | { | |
13 | // immutable cannot access mutable | |
14 | int i = 42; | |
15 | auto dg1 = delegate void() immutable { auto inner = i; }; | |
16 | ||
17 | // shared cannot access unshared | |
18 | int* p = &i; | |
19 | auto dg2 = delegate int() shared { return *p; }; | |
20 | assert(dg2() == i); | |
21 | ||
22 | // unshared can access shared | |
23 | shared j = 43; | |
24 | shared int* q = &j; | |
25 | auto dg3 = delegate int() { return *q; }; | |
26 | assert(dg2() == j); | |
27 | } |