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