1 // PERMUTE_ARGS:
2 
3 import core.stdc.stdio : printf;
4 import std.string : splitLines;
5 import std.utf : toUTF16, toUTF32;
6 
7 /***********************************************/
8 
test3()9 void test3()
10 {
11     char[] str;
12     str ~= "test"; // segfault
13 }
14 
15 /***********************************************/
16 
17 class A {
18 private:
19     int _i;
20 public:
this(int i)21     this(int i) { _i = i; }
i()22     int i() { return _i; };
23 }
24 
25 class B : A {
26 private:
27     char[] s;
28 public:
this(int i)29     this(int i) { super(i); }
30 }
31 
main()32 int main()
33 {
34     printf("Testing array of Chars\n");
35     CHAR();
36     printf("Testing array of WChars\n");
37     WCHAR();
38     printf("Testing array of DChars\n");
39     DCHAR();
40 
41     printf("Testing array of Bytes\n");
42     BYTE();
43     printf("Testing array of UBytes\n");
44     UBYTE();
45     printf("Testing array of Shorts\n");
46     SHORT();
47     printf("Testing array of UShorts\n");
48     USHORT();
49     printf("Testing array of Ints\n");
50     INT();
51     printf("Testing array of UInts\n");
52     UINT();
53     printf("Testing array of Longs\n");
54     LONG();
55     printf("Testing array of ULongs\n");
56     ULONG();
57     printf("Testing array of Floats\n");
58     FLOAT();
59     printf("Testing array of Doubles\n");
60     DOUBLE();
61     printf("Testing array of Reals\n");
62     REAL();
63 
64     printf("Testing multi-dim array of Chars\n");
65     MDCHAR();
66 
67     printf("Testing array of Objects\n");
68     CLASS();
69 
70     test3();
71     return 0;
72 }
73 
MDCHAR()74 void MDCHAR()
75 {
76     const int ITERS = 100;
77     alias char typ;
78     typ[][] str;
79 
80     str.length = ITERS;
81     for(int idx = 0; idx < ITERS; idx++) {
82         str[idx] = str[idx] ~ "TEST LINE\n";
83     }
84 
85     if(str.length != ITERS) printf("Length Error: %d\n",str.length);
86     if(str[0].length != 10) printf("Length Error: %d\n",str[0].length);
87     if(str[ITERS-1].sizeof != (typ[]).sizeof) printf("Size Error: %d\n",str[ITERS-1].sizeof);
88     if(str[ITERS-1][0].sizeof != (typ).sizeof) printf("Size Error: %d\n",str[ITERS-1][0].sizeof);
89 
90     foreach(s; str) {
91         int lstart;
92         foreach(int idx, char c; s) {
93             if(c == '\n') {
94                 typ[] t = s[lstart..idx];
95                 if(t != "TEST LINE") {
96                     printf("Error testing character array\n");
97                     break;
98                 }
99                 lstart = idx + 1;
100             }
101         }
102     }
103 
104     typ[] tmp;
105     foreach(char[] s; str) {
106         tmp = tmp ~ s;
107     }
108 
109     foreach(s; splitLines(cast(string)tmp)) {
110         int lstart;
111         foreach(int idx, char c; s) {
112             if(c == '\n') {
113                 if(s[lstart..idx] != "TEST LINE") {
114                     printf("Error testing character array\n");
115                     break;
116                 }
117                 lstart = idx + 1;
118             }
119         }
120     }
121 }
122 
CHAR()123 void CHAR()
124 {
125     const int ITERS = 1000;
126     alias char typ;
127     typ[] str;
128 
129     for(int idx = 0; idx < ITERS; idx++) {
130         str = str ~ "TEST LINE\n";
131     }
132 
133     if(str.length != (ITERS * 10)) printf("Length Error: %d\n",str.length);
134     if(str.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",str.sizeof);
135 
136     int lstart;
137     foreach(int idx, char c; str) {
138         if(c == '\n') {
139             if(str[lstart..idx] != "TEST LINE") {
140                 printf("Error testing character array\n");
141                 break;
142             }
143             lstart = idx + 1;
144         }
145     }
146 }
147 
WCHAR()148 void WCHAR()
149 {
150     const int ITERS = 1000;
151     alias wchar typ;
152     typ[] str;
153 
154     for(int idx = 0; idx < ITERS; idx++) {
155         str = str ~ toUTF16(cast(char[])"TEST LINE\n");
156     }
157 
158     if(str.length != (ITERS * 10)) printf("Length Error: %d\n",str.length);
159     if(str.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",str.sizeof);
160 
161     int lstart;
162     foreach(int idx, char c; str) {
163         if(c == '\n') {
164             if(str[lstart..idx] != toUTF16(cast(char[])"TEST LINE")) {
165                 printf("Error testing character array\n");
166                 break;
167             }
168             lstart = idx + 1;
169         }
170     }
171 }
172 
DCHAR()173 void DCHAR()
174 {
175     const int ITERS = 1000;
176     alias dchar typ;
177     typ[] str;
178 
179     for(int idx = 0; idx < ITERS; idx++) {
180         str = str ~ toUTF32(cast(char[])"TEST LINE\n");
181     }
182 
183     if(str.length != (ITERS * 10)) printf("Length Error: %d\n",str.length);
184     if(str.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",str.sizeof);
185 
186     int lstart;
187     foreach(int idx, char c; str) {
188         if(c == '\n') {
189             if(str[lstart..idx] != toUTF32(cast(char[])"TEST LINE")) {
190                 printf("Error testing character array\n");
191                 break;
192             }
193             lstart = idx + 1;
194         }
195     }
196 }
197 
BYTE()198 void BYTE()
199 {
200     const int ITERS = 100;
201     alias byte typ;
202     typ[] a;
203 
204     for(typ idx = 0; idx < ITERS; idx++) {
205         a ~= idx;
206     }
207 
208     if(a.length != ITERS) printf("Length Error: %d\n",a.length);
209     if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
210     for(int idx = 0; idx < ITERS; idx++) {
211         if(a[idx] != idx) {
212             printf("a Data Error: %d\n",a[idx]);
213             break;
214         }
215     }
216 
217 
218     typ[] b = a[];
219 
220     if(b.length != ITERS) printf("Length Error: %d\n",b.length);
221     if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
222     for(int idx = 0; idx < ITERS; idx++) {
223         if(b[idx] != idx) {
224             printf("b Data Error: %d\n",b[idx]);
225             break;
226         }
227     }
228     typ[] c;
229     c = a[0..ITERS/2] ~ b[ITERS/2..$];
230 
231 
232     if(c.length != ITERS) printf("Length Error: %d\n",c.length);
233     if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
234     for(int idx = 0; idx < ITERS; idx++) {
235         if(c[idx] != idx) {
236             printf("c Data Error: %d\n",c[idx]);
237             break;
238         }
239     }
240 }
241 
UBYTE()242 void UBYTE()
243 {
244     const int ITERS = 100;
245     alias ubyte typ;
246     typ[] a;
247 
248     for(typ idx = 0; idx < ITERS; idx++) {
249         a ~= idx;
250     }
251 
252     if(a.length != ITERS) printf("Length Error: %d\n",a.length);
253     if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
254     for(int idx = 0; idx < ITERS; idx++) {
255         if(a[idx] != idx) {
256             printf("a Data Error: %d\n",a[idx]);
257             break;
258         }
259     }
260 
261 
262     typ[] b = a[];
263 
264     if(b.length != ITERS) printf("Length Error: %d\n",b.length);
265     if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
266     for(int idx = 0; idx < ITERS; idx++) {
267         if(b[idx] != idx) {
268             printf("b Data Error: %d\n",b[idx]);
269             break;
270         }
271     }
272 
273     typ[] c;
274     c = a[0..ITERS/2] ~ b[ITERS/2..$];
275 
276 
277     if(c.length != ITERS) printf("Length Error: %d\n",c.length);
278     if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
279     for(int idx = 0; idx < ITERS; idx++) {
280         if(c[idx] != idx) {
281             printf("c Data Error: %d\n",c[idx]);
282             break;
283         }
284     }
285 }
286 
SHORT()287 void SHORT()
288 {
289     const int ITERS = 10000;
290     alias short typ;
291     typ[] a;
292 
293     for(typ idx = 0; idx < ITERS; idx++) {
294         a ~= idx;
295     }
296 
297     if(a.length != ITERS) printf("Length Error: %d\n",a.length);
298     if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
299     for(int idx = 0; idx < ITERS; idx++) {
300         if(a[idx] != idx) {
301             printf("a Data Error: %d\n",a[idx]);
302             break;
303         }
304     }
305 
306     typ[] b = a[];
307 
308     if(b.length != ITERS) printf("Length Error: %d\n",b.length);
309     if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
310     for(int idx = 0; idx < ITERS; idx++) {
311         if(b[idx] != idx) {
312             printf("b Data Error: %d\n",b[idx]);
313             break;
314         }
315     }
316 
317     typ[] c;
318     c = a[0..ITERS/2] ~ b[ITERS/2..$];
319 
320 
321     if(c.length != ITERS) printf("Length Error: %d\n",c.length);
322     if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
323     for(int idx = 0; idx < ITERS; idx++) {
324         if(c[idx] != idx) {
325             printf("c Data Error: %d\n",c[idx]);
326             break;
327         }
328     }
329 }
330 
USHORT()331 void USHORT()
332 {
333     const int ITERS = 10000;
334     alias ushort typ;
335     typ[] a;
336 
337     for(typ idx = 0; idx < ITERS; idx++) {
338         a ~= idx;
339     }
340 
341     if(a.length != ITERS) printf("Length Error: %d\n",a.length);
342     if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
343     for(int idx = 0; idx < ITERS; idx++) {
344         if(a[idx] != idx) {
345             printf("a Data Error: %d\n",a[idx]);
346             break;
347         }
348     }
349 
350     typ[] b = a[];
351 
352     if(b.length != ITERS) printf("Length Error: %d\n",b.length);
353     if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
354     for(int idx = 0; idx < ITERS; idx++) {
355         if(b[idx] != idx) {
356             printf("b Data Error: %d\n",b[idx]);
357             break;
358         }
359     }
360 
361     typ[] c;
362     c = a[0..ITERS/2] ~ b[ITERS/2..$];
363 
364 
365     if(c.length != ITERS) printf("Length Error: %d\n",c.length);
366     if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
367     for(int idx = 0; idx < ITERS; idx++) {
368         if(c[idx] != idx) {
369             printf("c Data Error: %d\n",c[idx]);
370             break;
371         }
372     }
373 }
374 
INT()375 void INT()
376 {
377     const int ITERS = 1000000;
378     alias int typ;
379     typ[] a;
380 
381     for(int idx = 0; idx < ITERS; idx++) {
382         a ~= idx;
383     }
384 
385     if(a.length != ITERS) printf("Length Error: %d\n",a.length);
386     if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
387     for(int idx = 0; idx < ITERS; idx++) {
388         if(a[idx] != idx) {
389             printf("a Data Error: %d\n",a[idx]);
390             break;
391         }
392     }
393 
394 
395     typ[] b = a[];
396 
397     if(b.length != ITERS) printf("Length Error: %d\n",b.length);
398     if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
399     for(int idx = 0; idx < ITERS; idx++) {
400         if(b[idx] != idx) {
401             printf("b Data Error: %d\n",b[idx]);
402             break;
403         }
404     }
405 
406     typ[] c;
407     c = a[0..ITERS/2] ~ b[ITERS/2..$];
408 
409 
410     if(c.length != ITERS) printf("Length Error: %d\n",c.length);
411     if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
412     for(int idx = 0; idx < ITERS; idx++) {
413         if(c[idx] != idx) {
414             printf("c Data Error: %d\n",c[idx]);
415             break;
416         }
417     }
418 }
419 
UINT()420 void UINT()
421 {
422     const int ITERS = 1000000;
423     alias uint typ;
424     typ[] a;
425 
426     for(int idx = 0; idx < ITERS; idx++) {
427         a ~= idx;
428     }
429 
430     if(a.length != ITERS) printf("Length Error: %d\n",a.length);
431     if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
432     for(int idx = 0; idx < ITERS; idx++) {
433         if(a[idx] != idx) {
434             printf("a Data Error: %d\n",a[idx]);
435             break;
436         }
437     }
438 
439 
440     typ[] b = a[];
441 
442     if(b.length != ITERS) printf("Length Error: %d\n",b.length);
443     if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
444     for(int idx = 0; idx < ITERS; idx++) {
445         if(b[idx] != idx) {
446             printf("b Data Error: %d\n",b[idx]);
447             break;
448         }
449     }
450 
451     typ[] c;
452     c = a[0..ITERS/2] ~ b[ITERS/2..$];
453 
454 
455     if(c.length != ITERS) printf("Length Error: %d\n",c.length);
456     if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
457     for(int idx = 0; idx < ITERS; idx++) {
458         if(c[idx] != idx) {
459             printf("c Data Error: %d\n",c[idx]);
460             break;
461         }
462     }
463 }
464 
LONG()465 void LONG()
466 {
467     const int ITERS = 1000000;
468     alias long typ;
469     typ[] a;
470 
471     for(int idx = 0; idx < ITERS; idx++) {
472         a ~= idx;
473     }
474 
475     if(a.length != ITERS) printf("Length Error: %d\n",a.length);
476     if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
477     for(int idx = 0; idx < ITERS; idx++) {
478         if(a[idx] != idx) {
479             printf("a Data Error: %d\n",a[idx]);
480             break;
481         }
482     }
483 
484     typ[] b = a[];
485 
486     if(b.length != ITERS) printf("Length Error: %d\n",b.length);
487     if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
488     for(int idx = 0; idx < ITERS; idx++) {
489         if(b[idx] != idx) {
490             printf("b Data Error: %d\n",b[idx]);
491             break;
492         }
493     }
494 
495     typ[] c;
496     c = a[0..ITERS/2] ~ b[ITERS/2..$];
497 
498 
499     if(c.length != ITERS) printf("Length Error: %d\n",c.length);
500     if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
501     for(int idx = 0; idx < ITERS; idx++) {
502         if(c[idx] != idx) {
503             printf("c Data Error: %d\n",c[idx]);
504             break;
505         }
506     }
507 }
508 
ULONG()509 void ULONG()
510 {
511     const int ITERS = 1000000;
512     alias ulong typ;
513     typ[] a;
514 
515     for(int idx = 0; idx < ITERS; idx++) {
516         a ~= idx;
517     }
518 
519     if(a.length != ITERS) printf("Length Error: %d\n",a.length);
520     if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
521     for(int idx = 0; idx < ITERS; idx++) {
522         if(a[idx] != idx) {
523             printf("a Data Error: %d\n",a[idx]);
524             break;
525         }
526     }
527 
528     typ[] b = a[];
529 
530     if(b.length != ITERS) printf("Length Error: %d\n",b.length);
531     if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
532     for(int idx = 0; idx < ITERS; idx++) {
533         if(b[idx] != idx) {
534             printf("b Data Error: %d\n",b[idx]);
535             break;
536         }
537     }
538 
539     typ[] c;
540     c = a[0..ITERS/2] ~ b[ITERS/2..$];
541 
542 
543     if(c.length != ITERS) printf("Length Error: %d\n",c.length);
544     if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
545     for(int idx = 0; idx < ITERS; idx++) {
546         if(c[idx] != idx) {
547             printf("c Data Error: %d\n",c[idx]);
548             break;
549         }
550     }
551 }
552 
FLOAT()553 void FLOAT()
554 {
555     const int ITERS = 1000000;
556     alias float typ;
557     typ[] a;
558 
559     for(int idx = 0; idx < ITERS; idx++) {
560         a ~= idx;
561     }
562 
563     if(a.length != ITERS) printf("Length Error: %d\n",a.length);
564     if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
565     for(int idx = 0; idx < ITERS; idx++) {
566         if(a[idx] != idx) {
567             printf("a Data Error: %d\n",a[idx]);
568             break;
569         }
570     }
571 
572     typ[] b = a[];
573 
574     if(b.length != ITERS) printf("Length Error: %d\n",b.length);
575     if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
576     for(int idx = 0; idx < ITERS; idx++) {
577         if(b[idx] != idx) {
578             printf("b Data Error: %d\n",b[idx]);
579             break;
580         }
581     }
582 
583     typ[] c;
584     c = a[0..ITERS/2] ~ b[ITERS/2..$];
585 
586 
587     if(c.length != ITERS) printf("Length Error: %d\n",c.length);
588     if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
589     for(int idx = 0; idx < ITERS; idx++) {
590         if(c[idx] != idx) {
591             printf("c Data Error: %d\n",c[idx]);
592             break;
593         }
594     }
595 }
596 
DOUBLE()597 void DOUBLE()
598 {
599     const int ITERS = 1000000;
600     alias double typ;
601     typ[] a;
602 
603     for(int idx = 0; idx < ITERS; idx++) {
604         a ~= idx;
605     }
606 
607     if(a.length != ITERS) printf("Length Error: %d\n",a.length);
608     if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
609     for(int idx = 0; idx < ITERS; idx++) {
610         if(a[idx] != idx) {
611             printf("a Data Error: %d\n",a[idx]);
612             break;
613         }
614     }
615 
616     typ[] b = a[];
617 
618     if(b.length != ITERS) printf("Length Error: %d\n",b.length);
619     if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
620     for(int idx = 0; idx < ITERS; idx++) {
621         if(b[idx] != idx) {
622             printf("b Data Error: %d\n",b[idx]);
623             break;
624         }
625     }
626 
627     typ[] c;
628     c = a[0..ITERS/2] ~ b[ITERS/2..$];
629 
630 
631     if(c.length != ITERS) printf("Length Error: %d\n",c.length);
632     if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
633     for(int idx = 0; idx < ITERS; idx++) {
634         if(c[idx] != idx) {
635             printf("c Data Error: %d\n",c[idx]);
636             break;
637         }
638     }
639 }
640 
REAL()641 void REAL()
642 {
643     const int ITERS = 1000000;
644     alias real typ;
645     typ[] a;
646 
647     for(int idx = 0; idx < ITERS; idx++) {
648         a ~= idx;
649     }
650 
651     if(a.length != ITERS) printf("Length Error: %d\n",a.length);
652     if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
653     for(int idx = 0; idx < ITERS; idx++) {
654         if(a[idx] != idx) {
655             printf("a Data Error: %d\n",a[idx]);
656             break;
657         }
658     }
659 
660     typ[] b = a[];
661 
662     if(b.length != ITERS) printf("Length Error: %d\n",b.length);
663     if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
664     for(int idx = 0; idx < ITERS; idx++) {
665         if(b[idx] != idx) {
666             printf("b Data Error: %d\n",b[idx]);
667             break;
668         }
669     }
670 
671     typ[] c;
672     c = a[0..ITERS/2] ~ b[ITERS/2..$];
673 
674 
675     if(c.length != ITERS) printf("Length Error: %d\n",c.length);
676     if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
677     for(int idx = 0; idx < ITERS; idx++) {
678         if(c[idx] != idx) {
679             printf("c Data Error: %d\n",c[idx]);
680             break;
681         }
682     }
683 }
684 
CLASS()685 void CLASS()
686 {
687     const int ITERS = 1000000;
688     alias B typ;
689     typ[] a;
690 
691     for(int idx = 0; idx < ITERS; idx++) {
692         typ tc = new typ(idx);
693         a ~= tc;
694     }
695 
696     if(a.length != ITERS) printf("Length Error: %d\n",a.length);
697     if(a.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",a.sizeof);
698     for(int idx = 0; idx < ITERS; idx++) {
699         if(a[idx].i != idx) {
700             printf("a Data Error: %d\n",a[idx].i);
701             break;
702         }
703     }
704 
705     typ[] b = a[];
706 
707     if(b.length != ITERS) printf("Length Error: %d\n",b.length);
708     if(b.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",b.sizeof);
709     for(int idx = 0; idx < ITERS; idx++) {
710         if(b[idx].i != idx) {
711             printf("b Data Error: %d\n",b[idx].i);
712             break;
713         }
714     }
715 
716     typ[] c;
717     c = a[0..ITERS/2] ~ b[ITERS/2..$];
718 
719     if(c.length != ITERS) printf("Length Error: %d\n",c.length);
720     if(c.sizeof != (typ[]).sizeof) printf("Size Error: %d\n",c.sizeof);
721     for(int idx = 0; idx < ITERS; idx++) {
722         if(c[idx].i != idx) {
723             printf("c Data Error: %d\n",c[idx].i);
724             break;
725         }
726     }
727 }
728