]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gdc.test/fail_compilation/test15306.d
d: Import dmd b8384668f, druntime e6caaab9, phobos 5ab9ad256 (v2.098.0-beta.1)
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / fail_compilation / test15306.d
CommitLineData
b4c522fa 1/*
b4c522fa
IB
2TEST_OUTPUT:
3---
5fee5ec3
IB
4fail_compilation/test15306.d(15): Error: `immutable` delegate `test15306.main.__dgliteral2` cannot access mutable data `i`
5fail_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
11void 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}