Debian Codegraph @

gcc/testsuite/gdc.test/fail_compilation/nogc1.d

raw
1 // REQUIRED_ARGS: -o-
2
3 /***************** NewExp *******************/
4
5 struct S1 { }
6 struct S2 { this(int); }
7 struct S3 { this(int) @nogc; }
8
9 /*
10 TEST_OUTPUT:
11 ---
12 fail_compilation/nogc1.d(23): Error: allocating with `new` causes a GC allocation in `@nogc` function `testNew`
13 fail_compilation/nogc1.d(25): Error: allocating with `new` causes a GC allocation in `@nogc` function `testNew`
14 fail_compilation/nogc1.d(26): Error: allocating with `new` causes a GC allocation in `@nogc` function `testNew`
15 fail_compilation/nogc1.d(28): Error: allocating with `new` causes a GC allocation in `@nogc` function `testNew`
16 fail_compilation/nogc1.d(29): Error: `@nogc` function `nogc1.testNew` cannot call non-@nogc constructor `nogc1.S2.this`
17 fail_compilation/nogc1.d(30): Error: allocating with `new` causes a GC allocation in `@nogc` function `testNew`
18 fail_compilation/nogc1.d(32): Error: allocating with `new` causes a GC allocation in `@nogc` function `testNew`
19 ---
20 */
21 @nogc void testNew()
22 {
23 int* p1 = new int;
24
25 int[] a1 = new int[3];
26 int[][] a2 = new int[][](2, 3);
27
28 S1* ps1 = new S1();
29 S2* ps2 = new S2(1);
30 S3* ps3 = new S3(1);
31
32 Object o1 = new Object();
33 }
34
35 /*
36 TEST_OUTPUT:
37 ---
38 fail_compilation/nogc1.d(48): Error: allocating with `new` causes a GC allocation in `@nogc` function `testNewScope`
39 fail_compilation/nogc1.d(50): Error: allocating with `new` causes a GC allocation in `@nogc` function `testNewScope`
40 fail_compilation/nogc1.d(51): Error: allocating with `new` causes a GC allocation in `@nogc` function `testNewScope`
41 fail_compilation/nogc1.d(53): Error: allocating with `new` causes a GC allocation in `@nogc` function `testNewScope`
42 fail_compilation/nogc1.d(54): Error: `@nogc` function `nogc1.testNewScope` cannot call non-@nogc constructor `nogc1.S2.this`
43 fail_compilation/nogc1.d(55): Error: allocating with `new` causes a GC allocation in `@nogc` function `testNewScope`
44 ---
45 */
46 @nogc void testNewScope()
47 {
48 scope int* p1 = new int;
49
50 scope int[] a1 = new int[3];
51 scope int[][] a2 = new int[][](2, 3);
52
53 scope S1* ps1 = new S1();
54 scope S2* ps2 = new S2(1);
55 scope S3* ps3 = new S3(1);
56
57 scope Object o1 = new Object(); // no error
58 scope o2 = new Object(); // no error
59 }