d: Merge upstream dmd, druntime 4c18eed967, phobos d945686a4.
[official-gcc.git] / gcc / testsuite / gdc.test / fail_compilation / test15306.d
blobff532aea220aba820883d88a99ef8146a5d19842
1 /*
2 TEST_OUTPUT:
3 ---
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`
6 ---
7 */
9 // https://issues.dlang.org/show_bug.cgi?id=15306
11 void main()
13 // immutable cannot access mutable
14 int i = 42;
15 auto dg1 = delegate void() immutable { auto inner = i; };
17 // shared cannot access unshared
18 int* p = &i;
19 auto dg2 = delegate int() shared { return *p; };
20 assert(dg2() == i);
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);