Debian Codegraph @

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

raw
1 // REQUIRED_ARGS: -o-
2
3 /***************** CatExp *******************/
4
5 /*
6 TEST_OUTPUT:
7 ---
8 fail_compilation/nogc2.d(20): Error: concatenating with operator `~` causes a GC allocation in `@nogc` function `testCat`
9 fail_compilation/nogc2.d(21): Error: concatenating with operator `~` causes a GC allocation in `@nogc` function `testCat`
10 fail_compilation/nogc2.d(22): Error: concatenating with operator `~` causes a GC allocation in `@nogc` function `testCat`
11 fail_compilation/nogc2.d(24): Error: concatenating with operator `~` causes a GC allocation in `@nogc` function `testCat`
12 fail_compilation/nogc2.d(25): Error: concatenating with operator `~` causes a GC allocation in `@nogc` function `testCat`
13 fail_compilation/nogc2.d(26): Error: concatenating with operator `~` causes a GC allocation in `@nogc` function `testCat`
14 fail_compilation/nogc2.d(27): Error: concatenating with operator `~` causes a GC allocation in `@nogc` function `testCat`
15 fail_compilation/nogc2.d(28): Error: concatenating with operator `~` causes a GC allocation in `@nogc` function `testCat`
16 ---
17 */
18 @nogc void testCat(int[] a, string s)
19 {
20 int[] a1 = a ~ a;
21 int[] a2 = a ~ 1;
22 int[] a3 = 1 ~ a;
23
24 string s1 = s ~ s;
25 string s2 = s ~ "a";
26 string s3 = "a" ~ s;
27 string s4 = s ~ 'c';
28 string s5 = 'c' ~ s;
29
30 string s6 = "a" ~ "b"; // no error
31 string s7 = "a" ~ 'c'; // no error
32 string s8 = 'c' ~ "b"; // no error
33 }
34
35 /***************** CatAssignExp *******************/
36
37 /*
38 TEST_OUTPUT:
39 ---
40 fail_compilation/nogc2.d(47): Error: appending to this array with operator `~=` causes a GC allocation in `@nogc` function `testCatAssign`
41 fail_compilation/nogc2.d(49): Error: appending to this array with operator `~=` causes a GC allocation in `@nogc` function `testCatAssign`
42 fail_compilation/nogc2.d(50): Error: appending to this array with operator `~=` causes a GC allocation in `@nogc` function `testCatAssign`
43 ---
44 */
45 @nogc void testCatAssign(int[] a, string s)
46 {
47 a ~= 1;
48
49 s ~= "a";
50 s ~= 'c';
51 }
52
53 /***************** ArrayLiteralExp *******************/
54
55 @nogc int* barA();
56
57 /*
58 TEST_OUTPUT:
59 ---
60 fail_compilation/nogc2.d(69): Error: this array literal causes a GC allocation in `@nogc` function `testArray`
61 fail_compilation/nogc2.d(70): Error: this array literal causes a GC allocation in `@nogc` function `testArray`
62 ---
63 */
64 @nogc void testArray()
65 {
66 enum arrLiteral = [null, null];
67
68 int* p;
69 auto a = [p, p, barA()];
70 a = arrLiteral;
71 }
72
73 /***************** AssocArrayLiteralExp *******************/
74
75 /*
76 TEST_OUTPUT:
77 ---
78 fail_compilation/nogc2.d(86): Error: this associative array literal causes a GC allocation in `@nogc` function `testAssocArray`
79 fail_compilation/nogc2.d(87): Error: this associative array literal causes a GC allocation in `@nogc` function `testAssocArray`
80 ---
81 */
82 @nogc void testAssocArray()
83 {
84 enum aaLiteral = [10: 100];
85
86 auto aa = [1:1, 2:3, 4:5];
87 aa = aaLiteral;
88 }
89
90 /***************** IndexExp *******************/
91
92 /*
93 TEST_OUTPUT:
94 ---
95 fail_compilation/nogc2.d(100): Error: assigning this associative array element causes a GC allocation in `@nogc` function `testIndex`
96 ---
97 */
98 @nogc void testIndex(int[int] aa)
99 {
100 aa[1] = 0;
101 int n = aa[1];
102 }