1 // REQUIRED_ARGS: -vgc -o- 2 // PERMUTE_ARGS: 3 4 /***************** CatExp *******************/ 5 6 /* 7 TEST_OUTPUT: 8 --- 9 compilable/vgc2.d(21): vgc: operator ~ may cause GC allocation 10 compilable/vgc2.d(22): vgc: operator ~ may cause GC allocation 11 compilable/vgc2.d(23): vgc: operator ~ may cause GC allocation 12 compilable/vgc2.d(25): vgc: operator ~ may cause GC allocation 13 compilable/vgc2.d(26): vgc: operator ~ may cause GC allocation 14 compilable/vgc2.d(27): vgc: operator ~ may cause GC allocation 15 compilable/vgc2.d(28): vgc: operator ~ may cause GC allocation 16 compilable/vgc2.d(29): vgc: operator ~ may cause GC allocation 17 --- 18 */ testCat(int[]a,string s)19void 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 compilable/vgc2.d(48): vgc: operator ~= may cause GC allocation 42 compilable/vgc2.d(50): vgc: operator ~= may cause GC allocation 43 compilable/vgc2.d(51): vgc: operator ~= may cause GC allocation 44 --- 45 */ testCatAssign(int[]a,string s)46void testCatAssign(int[] a, string s) 47 { 48 a ~= 1; 49 50 s ~= "a"; 51 s ~= 'c'; 52 } 53 54 /***************** ArrayLiteralExp *******************/ 55 56 int* barA(); 57 58 /* 59 TEST_OUTPUT: 60 --- 61 compilable/vgc2.d(70): vgc: array literal may cause GC allocation 62 compilable/vgc2.d(71): vgc: array literal may cause GC allocation 63 --- 64 */ testArray()65void 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 compilable/vgc2.d(87): vgc: associative array literal may cause GC allocation 80 compilable/vgc2.d(88): vgc: associative array literal may cause GC allocation 81 --- 82 */ testAssocArray()83void 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 compilable/vgc2.d(102): vgc: indexing an associative array may cause GC allocation 97 compilable/vgc2.d(103): vgc: indexing an associative array may cause GC allocation 98 --- 99 */ testIndex(int[int]aa)100void testIndex(int[int] aa) 101 { 102 aa[1] = 0; 103 int n = aa[1]; 104 } 105