]>
Commit | Line | Data |
---|---|---|
b4c522fa | 1 | /* |
5fee5ec3 | 2 | REQUIRED_ARGS: -preview=dip1000 |
b4c522fa IB |
3 | TEST_OUTPUT: |
4 | --- | |
5fee5ec3 IB |
5 | fail_compilation/test16193.d(38): Error: function `test16193.abc` is `@nogc` yet allocates closures with the GC |
6 | fail_compilation/test16193.d(40): test16193.abc.__foreachbody2 closes over variable x at fail_compilation/test16193.d(39) | |
b4c522fa IB |
7 | --- |
8 | */ | |
5fee5ec3 IB |
9 | //fail_compilation/test16193.d(22): To enforce `@safe`, the compiler allocates a closure unless `opApply()` uses `scope` |
10 | //fail_compilation/test16193.d(34): To enforce `@safe`, the compiler allocates a closure unless `opApply()` uses `scope` | |
11 | //fail_compilation/test16193.d(41): To enforce `@safe`, the compiler allocates a closure unless `opApply()` uses `scope` | |
b4c522fa IB |
12 | |
13 | // https://issues.dlang.org/show_bug.cgi?id=16193 | |
14 | ||
15 | struct S { | |
16 | int opApply(int delegate(int) dg) @nogc; | |
17 | } | |
18 | ||
19 | void foo() { | |
20 | int x = 0; | |
21 | foreach(i; S.init) { | |
22 | x++; | |
23 | } | |
24 | } | |
25 | ||
26 | struct T { | |
27 | int opApply(scope int delegate(int) dg) @nogc; | |
28 | } | |
29 | ||
30 | ||
31 | void bar() @nogc { | |
32 | int x = 0; | |
33 | foreach(i; T.init) { | |
34 | x++; | |
35 | } | |
36 | } | |
37 | ||
38 | void abc() @nogc { | |
39 | int x = 0; | |
40 | foreach(i; S.init) { | |
41 | x++; | |
42 | } | |
43 | } | |
44 |