| 1 |
// REQUIRED_ARGS: -vgc -o- |
| 2 |
// PERMUTE_ARGS: |
| 3 |
|
| 4 |
/***************** NewExp *******************/ |
| 5 |
|
| 6 |
struct S1 { } |
| 7 |
struct S2 { this(int); } |
| 8 |
struct S3 { this(int) @nogc; } |
| 9 |
|
| 10 |
/* |
| 11 |
TEST_OUTPUT: |
| 12 |
--- |
| 13 |
compilable/vgc1.d(25): vgc: `new` causes a GC allocation |
| 14 |
compilable/vgc1.d(27): vgc: `new` causes a GC allocation |
| 15 |
compilable/vgc1.d(28): vgc: `new` causes a GC allocation |
| 16 |
compilable/vgc1.d(30): vgc: `new` causes a GC allocation |
| 17 |
compilable/vgc1.d(31): vgc: `new` causes a GC allocation |
| 18 |
compilable/vgc1.d(32): vgc: `new` causes a GC allocation |
| 19 |
compilable/vgc1.d(34): vgc: `new` causes a GC allocation |
| 20 |
--- |
| 21 |
*/ |
| 22 |
|
| 23 |
void testNew() |
| 24 |
{ |
| 25 |
int* p1 = new int; |
| 26 |
|
| 27 |
int[] a1 = new int[3]; |
| 28 |
int[][] a2 = new int[][](2, 3); |
| 29 |
|
| 30 |
S1* ps1 = new S1(); |
| 31 |
S2* ps2 = new S2(1); |
| 32 |
S3* ps3 = new S3(1); |
| 33 |
|
| 34 |
Object o1 = new Object(); |
| 35 |
} |
| 36 |
|
| 37 |
/* |
| 38 |
TEST_OUTPUT: |
| 39 |
--- |
| 40 |
compilable/vgc1.d(51): vgc: `new` causes a GC allocation |
| 41 |
compilable/vgc1.d(53): vgc: `new` causes a GC allocation |
| 42 |
compilable/vgc1.d(54): vgc: `new` causes a GC allocation |
| 43 |
compilable/vgc1.d(56): vgc: `new` causes a GC allocation |
| 44 |
compilable/vgc1.d(57): vgc: `new` causes a GC allocation |
| 45 |
compilable/vgc1.d(58): vgc: `new` causes a GC allocation |
| 46 |
--- |
| 47 |
*/ |
| 48 |
|
| 49 |
void testNewScope() |
| 50 |
{ |
| 51 |
scope int* p1 = new int; |
| 52 |
|
| 53 |
scope int[] a1 = new int[3]; |
| 54 |
scope int[][] a2 = new int[][](2, 3); |
| 55 |
|
| 56 |
scope S1* ps1 = new S1(); |
| 57 |
scope S2* ps2 = new S2(1); |
| 58 |
scope S3* ps3 = new S3(1); |
| 59 |
|
| 60 |
scope Object o1 = new Object(); // no error |
| 61 |
scope o2 = new Object(); // no error |
| 62 |
scope Object o3; |
| 63 |
o3 = o2; // no error |
| 64 |
} |
| 65 |
|
| 66 |
/***************** DeleteExp *******************/ |
| 67 |
|
| 68 |
void testDelete(int* p, Object o, S1* s) |
| 69 |
{ |
| 70 |
destroy(p); |
| 71 |
destroy(o); |
| 72 |
destroy(s); |
| 73 |
} |