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