Debian Codegraph @

gcc/testsuite/gdc.test/fail_compilation/test21912.d

raw
1 /*
2 PERMUTE_ARGS: -preview=dip1000
3 TEST_OUTPUT:
4 ---
5 fail_compilation/test21912.d(28): Error: function `test21912.escapeParam` is `@nogc` yet allocates closure for `escapeParam()` with the GC
6 fail_compilation/test21912.d(30): delegate `() => i` closes over variable `i`
7 fail_compilation/test21912.d(28): `i` declared here
8 fail_compilation/test21912.d(33): Error: function `test21912.escapeAssign` is `@nogc` yet allocates closure for `escapeAssign()` with the GC
9 fail_compilation/test21912.d(35): delegate `() => i` closes over variable `i`
10 fail_compilation/test21912.d(33): `i` declared here
11 fail_compilation/test21912.d(44): Error: function `test21912.escapeAssignRef` is `@nogc` yet allocates closure for `escapeAssignRef()` with the GC
12 fail_compilation/test21912.d(46): delegate `() => i` closes over variable `i`
13 fail_compilation/test21912.d(44): `i` declared here
14 fail_compilation/test21912.d(55): Error: function `test21912.escapeParamInferred` is `@nogc` yet allocates closure for `escapeParamInferred()` with the GC
15 fail_compilation/test21912.d(57): delegate `() => i` closes over variable `i`
16 fail_compilation/test21912.d(55): `i` declared here
17 ---
18 */
19 @nogc:
20
21 alias Dg = @nogc int delegate();
22
23 Dg identity(return scope Dg dg)
24 {
25 return dg;
26 }
27
28 Dg escapeParam(int i)
29 {
30 return identity(() => i);
31 }
32
33 Dg escapeAssign(int i, return scope Dg dg)
34 {
35 dg = () => i;
36 return dg;
37 }
38
39 ref Dg identityR(return ref scope Dg dg)
40 {
41 return dg;
42 }
43
44 ref Dg escapeAssignRef(int i, return ref scope Dg dg)
45 {
46 dg = () => i;
47 return dg;
48 }
49
50 auto identityInferred(Dg dg)
51 {
52 return dg;
53 }
54
55 Dg escapeParamInferred(int i)
56 {
57 return identityInferred(() => i);
58 }