Debian Codegraph @

gcc/testsuite/gdc.test/runnable/betterc.d

raw
1 /* REQUIRED_ARGS: -betterC
2 PERMUTE_ARGS:
3 */
4
5
6 void test(int ij)
7 {
8 assert(ij);
9 #line 100 "anotherfile"
10 assert(ij,"it is not zero");
11 }
12
13 /*******************************************/
14 // https://issues.dlang.org/show_bug.cgi?id=18010
15
16 void test1()
17 {
18 int[10] a1 = void;
19 int[10] a2 = void;
20 a1[] = a2[];
21 }
22
23 void test2(int[] a1, int[] a2)
24 {
25 a1[] = a2[];
26 }
27
28 /*******************************************/
29 // https://issues.dlang.org/show_bug.cgi?id=17843
30
31 struct S
32 {
33 double d = 0.0;
34 int[] x;
35 }
36
37 /*******************************************/
38
39 extern (C) void main()
40 {
41 test(1);
42 test18472();
43 testRuntimeLowerings();
44 test18457();
45 test20737();
46 }
47
48 /*******************************************/
49 // https://issues.dlang.org/show_bug.cgi?id=17605
50
51 extern (C) void test17605()
52 {
53 int a;
54 enum bool works = __traits(compiles, { a = 1; });
55 a = 1;
56 }
57
58 /*******************************************/
59 // https://issues.dlang.org/show_bug.cgi?id=18472
60
61 void test18472()
62 {
63 version(D_LP64)
64 {
65 enum b = typeid(size_t) is typeid(ulong);
66 }
67 else
68 {
69 enum b = typeid(size_t) is typeid(uint);
70 }
71
72 assert(b);
73 }
74
75 /*******************************************/
76 // https://issues.dlang.org/show_bug.cgi?id=18493
77
78 struct S18493
79 {
80 this(this) nothrow { } // Since this is attributed with `nothrow` there should be no error about using
81 // try-catch with -betterC
82 ~this() { }
83 }
84
85 struct S18493_2
86 {
87 S18493 s1;
88 S18493 s2;
89 }
90
91 /******************************************************
92 * tests to ensure there is sufficient runtime support
93 * in imported object.d
94 */
95 mixin template initArray()
96 {
97 static if (is(T == bool))
98 {
99 T[6] a1 = [true, false, true, true, false, true];
100 }
101 else static if (is(T == Sint))
102 {
103 T[6] a1 = [Sint(1), Sint(2), Sint(3), Sint(1), Sint(2), Sint(3)];
104 }
105 else
106 {
107 T[6] a1 = [1,2,3,1,2,3];
108 }
109 }
110
111 struct Sint
112 {
113 int x;
114 this(int v) { x = v;}
115 }
116
117 void testRuntimeLowerings()
118 {
119 // test call to `object.__equals`
120 void test__equals(T)()
121 {
122 mixin initArray;
123
124 assert(a1[0..3] == a1[3..$]);
125 }
126
127 test__equals!int;
128 test__equals!uint;
129 test__equals!long;
130 test__equals!ulong;
131 test__equals!short;
132 test__equals!ushort;
133 test__equals!byte;
134 test__equals!dchar;
135 test__equals!wchar;
136 test__equals!ubyte;
137 test__equals!char;
138 test__equals!(const char);
139 test__equals!bool;
140 test__equals!Sint;
141
142 // test call to `object.__cmp`
143 void test__cmp(T)()
144 {
145 mixin initArray;
146
147 assert(a1[0..3] >= a1[3..$]);
148 assert(a1[0..3] <= a1[3..$]);
149 }
150
151 test__cmp!int;
152 test__cmp!uint;
153 test__cmp!long;
154 test__cmp!ulong;
155 test__cmp!short;
156 test__cmp!ushort;
157 test__cmp!byte;
158 test__cmp!dchar;
159 test__cmp!wchar;
160 test__cmp!ubyte;
161 test__cmp!char;
162 test__cmp!(const char);
163 test__cmp!bool;
164 test__cmp!Sint;
165
166 // test call to `object.__switch``
167 auto s = "abc";
168 switch(s)
169 {
170 case "abc":
171 break;
172 default:
173 break;
174 }
175 }
176
177 /**********************************************/
178 // https://issues.dlang.org/show_bug.cgi?id=18457
179
180 __gshared int dtor;
181
182 struct S18457
183 {
184 int a = 3;
185 ~this() { a = 0; ++dtor; }
186 }
187
188 S18457 myFunction()
189 {
190 S18457 s = S18457();
191 return s;
192 }
193
194 void test18457()
195 {
196 {
197 S18457 s = myFunction();
198 assert(s.a == 3);
199 assert(dtor == 0);
200 }
201 assert(dtor == 1);
202 }
203
204 /**********************************************/
205 // https://issues.dlang.org/show_bug.cgi?id=20737
206 int tlsVar;
207
208 int test20737()
209 {
210 tlsVar = 123;
211 return 0;
212 }
213
214 /*******************************************/
215 // https://issues.dlang.org/show_bug.cgi?id=22427
216 void test22427()
217 {
218 if("a" == "a")
219 return;
220
221 char[] p;
222 auto a = cast(int[])p;
223 }