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