| 1 |
// REQUIRED_ARGS: -vgc -o- |
| 2 |
// PERMUTE_ARGS: |
| 3 |
|
| 4 |
/***************** AssignExp *******************/ |
| 5 |
|
| 6 |
/* |
| 7 |
TEST_OUTPUT: |
| 8 |
--- |
| 9 |
compilable/vgc3.d(16): vgc: setting `length` may cause a GC allocation |
| 10 |
compilable/vgc3.d(17): vgc: setting `length` may cause a GC allocation |
| 11 |
compilable/vgc3.d(18): vgc: setting `length` may cause a GC allocation |
| 12 |
--- |
| 13 |
*/ |
| 14 |
void testArrayLength(int[] a) |
| 15 |
{ |
| 16 |
a.length = 3; |
| 17 |
a.length += 1; |
| 18 |
a.length -= 1; |
| 19 |
} |
| 20 |
|
| 21 |
/***************** CallExp *******************/ |
| 22 |
|
| 23 |
void barCall(); |
| 24 |
|
| 25 |
/* |
| 26 |
TEST_OUTPUT: |
| 27 |
--- |
| 28 |
--- |
| 29 |
*/ |
| 30 |
|
| 31 |
|
| 32 |
void testCall() |
| 33 |
{ |
| 34 |
auto fp = &barCall; |
| 35 |
(*fp)(); |
| 36 |
barCall(); |
| 37 |
} |
| 38 |
|
| 39 |
/****************** Closure ***********************/ |
| 40 |
|
| 41 |
@nogc void takeDelegate2(scope int delegate() dg) {} |
| 42 |
@nogc void takeDelegate3( int delegate() dg) {} |
| 43 |
|
| 44 |
/* |
| 45 |
TEST_OUTPUT: |
| 46 |
--- |
| 47 |
compilable/vgc3.d(51): vgc: using closure causes GC allocation |
| 48 |
compilable/vgc3.d(63): vgc: using closure causes GC allocation |
| 49 |
--- |
| 50 |
*/ |
| 51 |
auto testClosure1() |
| 52 |
{ |
| 53 |
int x; |
| 54 |
int bar() { return x; } |
| 55 |
return &bar; |
| 56 |
} |
| 57 |
void testClosure2() |
| 58 |
{ |
| 59 |
int x; |
| 60 |
int bar() { return x; } |
| 61 |
takeDelegate2(&bar); // no error |
| 62 |
} |
| 63 |
void testClosure3() |
| 64 |
{ |
| 65 |
int x; |
| 66 |
int bar() { return x; } |
| 67 |
takeDelegate3(&bar); |
| 68 |
} |