| 1 |
// REQUIRED_ARGS: -o- |
| 2 |
|
| 3 |
/***************** AssignExp *******************/ |
| 4 |
|
| 5 |
/* |
| 6 |
TEST_OUTPUT: |
| 7 |
--- |
| 8 |
fail_compilation/nogc3.d(15): Error: setting this array's `length` causes a GC allocation in `@nogc` function `testArrayLength` |
| 9 |
fail_compilation/nogc3.d(16): Error: setting this array's `length` causes a GC allocation in `@nogc` function `testArrayLength` |
| 10 |
fail_compilation/nogc3.d(17): Error: setting this array's `length` causes a GC allocation in `@nogc` function `testArrayLength` |
| 11 |
--- |
| 12 |
*/ |
| 13 |
@nogc void testArrayLength(int[] a) |
| 14 |
{ |
| 15 |
a.length = 3; |
| 16 |
a.length += 1; |
| 17 |
a.length -= 1; |
| 18 |
} |
| 19 |
|
| 20 |
/***************** CallExp *******************/ |
| 21 |
|
| 22 |
void barCall(); |
| 23 |
|
| 24 |
/* |
| 25 |
TEST_OUTPUT: |
| 26 |
--- |
| 27 |
fail_compilation/nogc3.d(34): Error: `@nogc` function `nogc3.testCall` cannot call non-@nogc function pointer `fp` |
| 28 |
fail_compilation/nogc3.d(35): Error: `@nogc` function `nogc3.testCall` cannot call non-@nogc function `nogc3.barCall` |
| 29 |
--- |
| 30 |
*/ |
| 31 |
@nogc void testCall() |
| 32 |
{ |
| 33 |
auto fp = &barCall; |
| 34 |
(*fp)(); |
| 35 |
barCall(); |
| 36 |
} |
| 37 |
|
| 38 |
/****************** Closure ***********************/ |
| 39 |
|
| 40 |
@nogc void takeDelegate2(scope int delegate() dg) {} |
| 41 |
@nogc void takeDelegate3( int delegate() dg) {} |
| 42 |
|
| 43 |
/* |
| 44 |
TEST_OUTPUT: |
| 45 |
--- |
| 46 |
fail_compilation/nogc3.d(54): Error: function `nogc3.testClosure1` is `@nogc` yet allocates closure for `testClosure1()` with the GC |
| 47 |
fail_compilation/nogc3.d(57): function `bar` closes over variable `x` |
| 48 |
fail_compilation/nogc3.d(56): `x` declared here |
| 49 |
fail_compilation/nogc3.d(66): Error: function `nogc3.testClosure3` is `@nogc` yet allocates closure for `testClosure3()` with the GC |
| 50 |
fail_compilation/nogc3.d(69): function `bar` closes over variable `x` |
| 51 |
fail_compilation/nogc3.d(68): `x` declared here |
| 52 |
--- |
| 53 |
*/ |
| 54 |
@nogc auto testClosure1() |
| 55 |
{ |
| 56 |
int x; |
| 57 |
int bar() { return x; } |
| 58 |
return &bar; |
| 59 |
} |
| 60 |
@nogc void testClosure2() |
| 61 |
{ |
| 62 |
int x; |
| 63 |
int bar() { return x; } |
| 64 |
takeDelegate2(&bar); // no error |
| 65 |
} |
| 66 |
@nogc void testClosure3() |
| 67 |
{ |
| 68 |
int x; |
| 69 |
int bar() { return x; } |
| 70 |
takeDelegate3(&bar); |
| 71 |
} |
| 72 |
|
| 73 |
/****************** ErrorExp ***********************/ |
| 74 |
|
| 75 |
/* |
| 76 |
TEST_OUTPUT: |
| 77 |
--- |
| 78 |
fail_compilation/nogc3.d(87): Error: this array literal causes a GC allocation in `@nogc` function `foo13702` |
| 79 |
fail_compilation/nogc3.d(88): Error: this array literal causes a GC allocation in `@nogc` function `foo13702` |
| 80 |
fail_compilation/nogc3.d(94): Error: this array literal causes a GC allocation in `@nogc` function `bar13702` |
| 81 |
fail_compilation/nogc3.d(93): Error: this array literal causes a GC allocation in `@nogc` function `bar13702` |
| 82 |
--- |
| 83 |
*/ |
| 84 |
int[] foo13702(bool b) @nogc |
| 85 |
{ |
| 86 |
if (b) |
| 87 |
return [1]; // error |
| 88 |
return 1 ~ [2]; // error |
| 89 |
} |
| 90 |
int[] bar13702(bool b) @nogc |
| 91 |
{ |
| 92 |
if (b) |
| 93 |
return [1]; // error <- no error report |
| 94 |
auto aux = 1 ~ [2]; // error |
| 95 |
return aux; |
| 96 |
} |