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