1 // REQUIRED_ARGS: -o- 2 // PERMUTE_ARGS: 3 4 /***************** NewExp *******************/ 5 6 struct S1 { } 7 struct S2 { this(int); } 8 struct S3 { this(int) @nogc; } 9 struct S4 { new(size_t); } 10 struct S5 { @nogc new(size_t); } 11 12 /* 13 TEST_OUTPUT: 14 --- 15 fail_compilation/nogc1.d(27): Error: cannot use 'new' in @nogc function 'nogc1.testNew' 16 fail_compilation/nogc1.d(29): Error: cannot use 'new' in @nogc function 'nogc1.testNew' 17 fail_compilation/nogc1.d(30): Error: cannot use 'new' in @nogc function 'nogc1.testNew' 18 fail_compilation/nogc1.d(32): Error: cannot use 'new' in @nogc function 'nogc1.testNew' 19 fail_compilation/nogc1.d(33): Error: @nogc function 'nogc1.testNew' cannot call non-@nogc constructor 'nogc1.S2.this' 20 fail_compilation/nogc1.d(34): Error: cannot use 'new' in @nogc function 'nogc1.testNew' 21 fail_compilation/nogc1.d(35): Error: @nogc function 'nogc1.testNew' cannot call non-@nogc allocator 'nogc1.S4.new' 22 fail_compilation/nogc1.d(38): Error: cannot use 'new' in @nogc function 'nogc1.testNew' 23 --- 24 */ testNew()25@nogc void testNew() 26 { 27 int* p1 = new int; 28 29 int[] a1 = new int[3]; 30 int[][] a2 = new int[][](2, 3); 31 32 S1* ps1 = new S1(); 33 S2* ps2 = new S2(1); 34 S3* ps3 = new S3(1); 35 S4* ps4 = new S4; 36 S5* ps5 = new S5; // no error 37 38 Object o1 = new Object(); 39 } 40 41 /* 42 TEST_OUTPUT: 43 --- 44 fail_compilation/nogc1.d(55): Error: cannot use 'new' in @nogc function 'nogc1.testNewScope' 45 fail_compilation/nogc1.d(57): Error: cannot use 'new' in @nogc function 'nogc1.testNewScope' 46 fail_compilation/nogc1.d(58): Error: cannot use 'new' in @nogc function 'nogc1.testNewScope' 47 fail_compilation/nogc1.d(60): Error: cannot use 'new' in @nogc function 'nogc1.testNewScope' 48 fail_compilation/nogc1.d(61): Error: @nogc function 'nogc1.testNewScope' cannot call non-@nogc constructor 'nogc1.S2.this' 49 fail_compilation/nogc1.d(62): Error: cannot use 'new' in @nogc function 'nogc1.testNewScope' 50 fail_compilation/nogc1.d(63): Error: @nogc function 'nogc1.testNewScope' cannot call non-@nogc allocator 'nogc1.S4.new' 51 --- 52 */ testNewScope()53@nogc void testNewScope() 54 { 55 scope int* p1 = new int; 56 57 scope int[] a1 = new int[3]; 58 scope int[][] a2 = new int[][](2, 3); 59 60 scope S1* ps1 = new S1(); 61 scope S2* ps2 = new S2(1); 62 scope S3* ps3 = new S3(1); 63 scope S4* ps4 = new S4; 64 scope S5* ps5 = new S5; // no error 65 66 scope Object o1 = new Object(); // no error 67 scope o2 = new Object(); // no error 68 } 69 70 /***************** DeleteExp *******************/ 71 72 /* 73 TEST_OUTPUT: 74 --- 75 fail_compilation/nogc1.d(82): Error: cannot use 'delete' in @nogc function 'nogc1.testDelete' 76 fail_compilation/nogc1.d(83): Error: cannot use 'delete' in @nogc function 'nogc1.testDelete' 77 fail_compilation/nogc1.d(84): Error: cannot use 'delete' in @nogc function 'nogc1.testDelete' 78 --- 79 */ testDelete(int * p,Object o,S1 * s)80@nogc void testDelete(int* p, Object o, S1* s) 81 { 82 delete p; 83 delete o; 84 delete s; 85 } 86