| 1 |
/* |
| 2 |
TEST_OUTPUT: |
| 3 |
--- |
| 4 |
fail_compilation/diag12829.d(15): Error: function `diag12829.test1` is `@nogc` yet allocates closure for `test1()` with the GC |
| 5 |
fail_compilation/diag12829.d(18): delegate `() { int y = x; }` closes over variable `x` |
| 6 |
fail_compilation/diag12829.d(17): `x` declared here |
| 7 |
fail_compilation/diag12829.d(22): function `bar` closes over variable `x` |
| 8 |
fail_compilation/diag12829.d(17): `x` declared here |
| 9 |
fail_compilation/diag12829.d(29): Error: function `diag12829.test2` is `@nogc` yet allocates closure for `test2()` with the GC |
| 10 |
fail_compilation/diag12829.d(34): function `foo` closes over variable `x` |
| 11 |
fail_compilation/diag12829.d(31): `x` declared here |
| 12 |
--- |
| 13 |
*/ |
| 14 |
|
| 15 |
auto test1() @nogc |
| 16 |
{ |
| 17 |
int x; |
| 18 |
void delegate() @nogc foo = () { |
| 19 |
int y = x; |
| 20 |
}; |
| 21 |
|
| 22 |
void bar() |
| 23 |
{ |
| 24 |
int y = x; |
| 25 |
} |
| 26 |
auto dg = &bar; |
| 27 |
} |
| 28 |
|
| 29 |
auto test2() @nogc |
| 30 |
{ |
| 31 |
int x; |
| 32 |
struct S |
| 33 |
{ |
| 34 |
void foo() |
| 35 |
{ |
| 36 |
int y = x; |
| 37 |
} |
| 38 |
} |
| 39 |
return S(); |
| 40 |
} |