1 // { dg-additional-sources "imports/runnable.d" }
2 // { dg-do run { target hw } }
3 // { dg-skip-if "needs gcc/config.d" { ! d_runtime } }
4
5 module runnable;
6
7 import imports.runnable;
8 import core.stdc.stdio;
9 import gcc.attribute;
10
11
12 /******************************************/
13 // https://bugzilla.gdcproject.org/show_bug.cgi?id=4
14
test4()15 void test4()
16 {
17 string str = "allo";
18 static assert(!__traits(compiles, str.reverse));
19 static assert(!__traits(compiles, str.sort));
20 }
21
22 /******************************************/
23 // https://bugzilla.gdcproject.org/show_bug.cgi?id=17
24
25 /**
26 * Parameters are not copied into a frame to be accessed from
27 * the method's __require function.
28 */
contractTest(string path)29 void contractTest(string path)
30 {
31 assert(path[0] == 't');
32 assert(path.length == 9);
33 assert(path[8] == 'i');
34 }
35
36 interface ModuleSaver
37 {
save(string str)38 void save(string str)
39 in
40 {
41 contractTest(str);
42 }
43 }
44
45 class ModuleWriter : ModuleSaver
46 {
save(string str)47 void save (string str)
48 in {}
49 body
50 {
51 }
52 }
53
test17()54 void test17()
55 {
56 (new ModuleWriter()).save ("test.0.mci");
57 }
58
59 /******************************************/
60 // https://bugzilla.gdcproject.org/show_bug.cgi?id=19
61
test19()62 void test19()
63 {
64 byte b;
65 --b = b;
66 }
67
68 /******************************************/
69 // https://bugzilla.gdcproject.org/show_bug.cgi?id=24
70
test24()71 void test24()
72 {
73 struct S24
74 {
75 char[1] b;
76 }
77
78 S24 a;
79
80 if (*a.b.ptr)
81 return;
82 }
83
84 /******************************************/
85 // https://bugzilla.gdcproject.org/show_bug.cgi?id=31
86
RedBlackTree(T,alias less)87 class RedBlackTree(T, alias less)
88 {
89 struct Range
90 {
91 @property empty() { }
92 }
93
94 Range opSlice()
95 {
96 return Range();
97 }
98 }
99
redBlackTree(alias less,E)100 auto redBlackTree(alias less, E)()
101 {
102 return new RedBlackTree!(E, less);
103 }
104
test31()105 void test31()
106 {
107 redBlackTree!((a){}, double)();
108 }
109
110 /******************************************/
111 // https://bugzilla.gdcproject.org/show_bug.cgi?id=35
112
113 /**
114 * Here the BinaryHeap instance uses an alias parameter and therefore
115 * the instance's functions (percolateDown) need to be generated in
116 * topNIndex->BinaryHeap scope and not in the declaration scope
117 * (module->BinaryHeap).
118 */
topNIndex()119 void topNIndex()()
120 {
121 bool indirectLess(int a, int b)
122 {
123 return a > b;
124 }
125
126 auto a = BinaryHeap!(indirectLess)();
127 }
128
BinaryHeap(alias less)129 struct BinaryHeap(alias less)
130 {
131 void percolateDown()
132 {
133 less(0, 1);
134 }
135 }
136
test35a()137 void test35a()
138 {
139 topNIndex();
140 }
141
142 /*
143 * Similar as test35a but with an additional indirection.
144 * The nested function chain for percolateDown should look like this:
145 * topNIndex2->BinaryHeap2->percolateDown.
146 */
topNIndex2()147 void topNIndex2()()
148 {
149 bool indirectLess(int a, int b)
150 {
151 return a > b;
152 }
153 auto a = BinaryHeap2!(S35b!(indirectLess)())();
154 }
155
S35b(alias a)156 struct S35b(alias a)
157 {
158 void foo()
159 {
160 a(0, 0);
161 }
162 }
163
BinaryHeap2(alias less)164 struct BinaryHeap2(alias less)
165 {
166 void percolateDown()
167 {
168 less.foo();
169 }
170 }
171
test35b()172 void test35b()
173 {
174 topNIndex2();
175 }
176
test35()177 void test35()
178 {
179 test35a();
180 test35b();
181 }
182
183 /******************************************/
184 // https://bugzilla.gdcproject.org/show_bug.cgi?id=36
185
186 /**
187 * Here getChar is a function in a template where template.isnested == false
188 * but getChar still is a nested function and needs to get a static chain
189 * containing test36a.
190 */
test36a()191 void test36a()(char val)
192 {
193 void error()
194 {
195 }
196
197 void getChar()()
198 {
199 error();
200 }
201
202 void parseString()
203 {
204 getChar();
205 }
206 }
207
208 /**
209 * Similar as test36a, but a little more complicated:
210 * Here getChar is nested in a struct template which is nested in a function.
211 * getChar's static chain still needs to contain test36b.
212 */
test36b()213 void test36b()(char val)
214 {
215 void error()
216 {
217 }
218
219 struct S(T)
220 {
221 void getChar()
222 {
223 error();
224 }
225 }
226
227
228 void parseString()
229 {
230 S!(int)().getChar();
231 }
232 }
233
234 /**
235 * If g had accessed a, the frontend would have generated a closure.
236 *
237 * As we do not access it, there's no closure. We have to be careful
238 * not to set a static chain for g containing test36c_1 though,
239 * as g can be called from outside (here from test1c). In the end
240 * we have to treat this as if everything in test36c_1 was declared
241 * at module scope.
242 */
test36c_1()243 auto test36c_1()
244 {
245 int a;
246 void c() {};
247 class Result
248 {
249 int b;
250 void g() { c(); /*a = 42;*/ }
251 }
252
253 return new Result();
254 }
255
test36c()256 void test36c()
257 {
258 test36c_1().g();
259 }
260
261 /**
262 * empty is a (private) function which is nested in lightPostprocess.
263 * At the same time it's a template instance, so it has to be declared as
264 * weak or otherwise one-only. imports/runnable.d creates another instance
265 * of Regex!char to verify that.
266 */
Parser(R)267 struct Parser(R)
268 {
269 @property program()
270 {
271 return Regex!char();
272 }
273 }
274
Regex(Char)275 struct Regex(Char)
276 {
277 @trusted lightPostprocess()
278 {
279 struct FixedStack(T)
280 {
281 @property empty() { return false; }
282 }
283 auto counterRange = FixedStack!uint();
284 }
285 }
286
test36d()287 void test36d()
288 {
289 auto parser = Parser!(char[])();
290 imports.runnable.test36d_1;
291 }
292
test36()293 void test36()
294 {
295 test36a('n');
296 test36b('n');
297 test36c();
298 test36d();
299 }
300
301 /******************************************/
302 // https://bugzilla.gdcproject.org/show_bug.cgi?id=37
303
304 struct S37
305 {
barS37306 int bar(const S37 s)
307 {
308 return 0;
309 }
310 }
311
test37()312 int test37()
313 {
314 S37 s;
315 return s.bar(s);
316 }
317
318 /******************************************/
319 // https://bugzilla.gdcproject.org/show_bug.cgi?id=43
320
test43()321 void test43()
322 {
323 import core.vararg;
324 import core.stdc.stdio;
325
326 void formatArray(ref va_list argptr)
327 {
328 auto a = va_arg!(const(float)[])(argptr);
329 foreach(f; a)
330 {
331 printf("%f\n", f);
332 }
333 }
334
335 void doFormat(TypeInfo[] arguments, va_list argptr)
336 {
337 formatArray(argptr);
338 }
339
340 void format(...)
341 {
342 doFormat(_arguments, _argptr);
343 }
344
345 format([1.0f, 2.0f, 3.0f]);
346 }
347
348 /******************************************/
349 // https://bugzilla.gdcproject.org/show_bug.cgi?id=47
350
Foo47()351 template Foo47()
352 {
353 void test47()
354 {
355 asm { "nop"; }
356 }
357 }
358
359 mixin Foo47!();
360
361 /******************************************/
362 // https://bugzilla.gdcproject.org/show_bug.cgi?id=51
363
364 struct S51
365 {
366 int x;
367 int pad;
368
thisS51369 this(this)
370 {
371 ++x;
372 }
373 }
374
test51()375 void test51()
376 {
377 S51 s;
378 auto sarr = new S51[1];
379 auto sarr2 = sarr;
380
381 // postblit all fields.
382 sarr2 ~= s;
383
384 assert (sarr2[0].x == 1);
385 assert (sarr2[1].x == 1);
386 assert (sarr[0].x == 0);
387 assert (s.x == 0);
388 }
389
390 /******************************************/
391 // https://bugzilla.gdcproject.org/show_bug.cgi?id=57
392
393 struct S57
394 {
395 int a;
396 long b;
397 // Doesn't happen for bigger structs
398 }
399
bar57()400 S57 bar57()
401 {
402 return S57(4, 42);
403 }
404
test57()405 void test57()
406 {
407 S57 s = bar57();
408 assert (s is S57(4, 42));
409 }
410
411 /******************************************/
412 // https://bugzilla.gdcproject.org/show_bug.cgi?id=66
413
test66()414 void test66()
415 {
416 int pos = 0;
417
418 foreach(x; 0 .. 64)
419 {
420 ++pos %= 4;
421 assert (pos != 4);
422 }
423 }
424
425 /******************************************/
426 // https://bugzilla.gdcproject.org/show_bug.cgi?id=67
427
428 __vector(float[4]) d[2]; // ICE
429
430
431 /******************************************/
432 // https://bugzilla.gdcproject.org/show_bug.cgi?id=115
433
test115()434 void test115()
435 {
436 union U
437 {
438 float f;
439 uint i;
440 }
441 float a = 123.0;
442 const l = U(a);
443
444 assert(l.i == U(a).i);
445 }
446
447 /******************************************/
448 // https://bugzilla.gdcproject.org/show_bug.cgi?id=121
449
450 immutable char C121 = void; // ICE
451
452 /******************************************/
453 // https://bugzilla.gdcproject.org/show_bug.cgi?id=127
454
455 int[0] test127a; // OK
456 int[1][0] test127b; // OK
457 int[0][1] test127c; // ICE
458
459 /******************************************/
460 // https://bugzilla.gdcproject.org/show_bug.cgi?id=131
461
462 struct S131
463 {
thisS131464 this(string ) { }
opAssignS131465 string opAssign(string v) { return v; }
466 }
467
test131()468 void test131()
469 {
470 S131[string] s;
471 s["foo"] = "bar";
472 }
473
474 /******************************************/
475 // https://bugzilla.gdcproject.org/show_bug.cgi?id=133
476
477 void delegate()[] D133;
478
test133a(void delegate ()dg)479 void test133a(void delegate() dg)
480 {
481 D133 ~= dg;
482 }
483
test133()484 void test133()
485 {
486 void nested()
487 {}
488 test133a(&nested);
489 }
490
491 /******************************************/
492 // https://bugzilla.gdcproject.org/show_bug.cgi?id=141
493
test141a(int a)494 bool test141a(int a)
495 {
496 return a > (a + 1);
497 }
498
test141()499 void test141()
500 {
501 assert(test141a(int.min) == false);
502 assert(test141a(int.max) == true);
503 }
504
505 /******************************************/
506 // https://bugzilla.gdcproject.org/show_bug.cgi?id=142
507
508 @attribute("noinline")
test142a()509 int test142a()()
510 {
511 return 142;
512 }
513
test142()514 void test142()
515 {
516 enum E142 = test142a();
517 }
518
519 /******************************************/
520 // https://bugzilla.gdcproject.org/show_bug.cgi?id=171
521
test171a()522 void test171a()
523 {
524 int count = 0;
525 short a = -1;
526 while (a != 0)
527 {
528 a >>>= 1;
529 count++;
530 assert(count <= 16);
531 }
532 }
533
test171b()534 void test171b()
535 {
536 uint[3] lhs = [99, 201, 300],
537 rhs = [-1, 0, 0];
538 long t = 0;
539
540 for (int i = 0; i < 3; i++)
541 {
542 t += lhs[i];
543 t -= rhs[i];
544 lhs[i] = cast(uint) t;
545 t >>= uint.sizeof * 8;
546 }
547
548 assert(lhs == [100, 200, 300]);
549 }
550
test171()551 void test171()
552 {
553 test171a();
554 test171b();
555 }
556
557 /******************************************/
558 // https://bugzilla.gdcproject.org/show_bug.cgi?id=179
559
560 struct S179a
561 {
562 @disable this(this);
563 }
564
565 struct S179b
566 {
567 S179a s1;
connect()568 void connect() { printf("this=%p\n", &this); }
569 }
570
571 class C179
572 {
573 private S179b s2;
value()574 ref S179b value() @property
575 {
576 printf("this=%p\n", &s2);
577 return s2;
578 }
579 }
580
test179()581 void test179()
582 {
583 C179 a = new C179;
584 a.value.connect();
585 }
586
587 /******************************************/
588 // https://bugzilla.gdcproject.org/show_bug.cgi?id=183
589
590 struct S183a
591 {
592 union I183a
593 {
594 struct
595 {
596 double x, y, z;
597 }
598 struct
599 {
600 double a, b, c;
601 }
602 }
603
604 I183a inner;
605
thisS183a606 this(double x, double y, double z)
607 {
608 this.inner.x = x;
609 this.inner.y = y;
610 this.inner.z = z;
611 }
612 }
613
614 struct S183b
615 {
get()616 @property get()
617 {
618 union Buf
619 {
620 void[0] result;
621 }
622 const Buf buf = { };
623 return buf.result;
624 }
625 }
626
627 struct S183c
628 {
getS183c629 @property get()
630 {
631 union Buf
632 {
633 TypeInfo info;
634 void[0] result;
635 }
636 const Buf buf = { };
637 return buf.result;
638 }
639 }
640
test183()641 void test183()
642 {
643 auto v1 = S183a(0, 0, 0);
644 auto v2 = S183b().get;
645 auto v3 = S183c().get;
646 }
647
648 /******************************************/
649 // https://bugzilla.gdcproject.org/show_bug.cgi?id=186
650
651 struct S186
652 {
653 union
654 {
655 struct
656 {
657 ubyte fieldA;
658 byte fieldB = -1;
659 byte fieldC = -1;
660 }
661 size_t _complete;
662 }
663
thisS186664 this(size_t complete)
665 {
666 this._complete = complete;
667 }
668 }
669
670 static if (size_t.sizeof == 8)
671 enum checkval = 0x0200000000000002;
672 else
673 enum checkval = 0x02000002;
674
check186(in S186 obj,byte fieldB)675 void check186(in S186 obj, byte fieldB)
676 {
677 assert(obj.fieldA == 2);
678 assert(obj.fieldB == 0);
679 assert(obj.fieldC == 0);
680 assert(obj._complete == checkval);
681 assert(fieldB == 0);
682 }
683
test186a(size_t val)684 void test186a(size_t val)
685 {
686 S186 obj = S186(val);
687 check186(obj, obj.fieldB);
688
689 assert(obj.fieldA == 2);
690 assert(obj.fieldB == 0);
691 assert(obj.fieldC == 0);
692 assert(obj._complete == checkval);
693
694 obj = S186(val);
695 check186(obj, obj.fieldB);
696
697 assert(obj.fieldA == 2);
698 assert(obj.fieldB == 0);
699 assert(obj.fieldC == 0);
700 assert(obj._complete == checkval);
701 }
702
test186()703 void test186()
704 {
705 test186a(checkval);
706 }
707
708 /******************************************/
709 // https://bugzilla.gdcproject.org/show_bug.cgi?id=187
710
711 align(1) struct S187b
712 {
713 align(1)
714 {
715 uint unpaddedA;
716 ushort unpaddedB;
717 }
718 }
719
720 struct S187a
721 {
722 S187b[3] unpaddedArray;
723 ubyte wontInitialize = ubyte.init;
724 }
725
726 struct S187
727 {
728 S187a interesting;
729 }
730
731
prepareStack()732 void prepareStack()
733 {
734 byte[255] stackGarbage;
735 foreach(i, ref b; stackGarbage)
736 {
737 b = cast(byte)(-i);
738 }
739 }
740
test187()741 void test187()
742 {
743 prepareStack();
744 auto a = S187(S187a());
745 assert(a.interesting.wontInitialize == 0);
746 }
747
748 /******************************************/
749 // https://bugzilla.gdcproject.org/show_bug.cgi?id=191
750
751 class C191
752 {
753 int count = 0;
754
testA()755 void testA()
756 {
757 class Inner
758 {
759 void test()
760 {
761 void localFunction()
762 {
763 if (++count != 5)
764 testA();
765 }
766 localFunction();
767 }
768 }
769 scope ic = new Inner();
770 ic.test();
771 }
772
testB()773 void testB()
774 {
775 class Inner
776 {
777 void test()
778 {
779 void localFunction()
780 {
781 void anotherLocalFunction()
782 {
783 if (++count != 10)
784 testB();
785 }
786 anotherLocalFunction();
787 }
788 localFunction();
789 }
790 }
791 scope ic = new Inner();
792 ic.test();
793 }
794
testC()795 void testC()
796 {
797 class Inner
798 {
799 int a = 1;
800
801 void test()
802 {
803 void localFunction()
804 {
805 count += a;
806 if (count != 15)
807 testC();
808 assert(a == 1);
809 }
810 localFunction();
811 }
812 }
813 scope ic = new Inner();
814 ic.test();
815 }
816
testD()817 void testD()
818 {
819 class Inner
820 {
821 void test()
822 {
823 int a = 1;
824
825 void localFunction()
826 {
827 count += a;
828 if (count != 20)
829 testD();
830 assert(a == 1);
831 }
832 localFunction();
833 }
834 }
835 scope ic = new Inner();
836 ic.test();
837 }
838
testE()839 void testE()
840 {
841 class Inner
842 {
843 int a = 1;
844
845 void test()
846 {
847 void localFunction()
848 {
849 void anotherLocalFunction()
850 {
851 count += a;
852 if (count != 25)
853 testE();
854 assert(a == 1);
855 }
856
857 anotherLocalFunction();
858 }
859
860 localFunction();
861 }
862 }
863 scope ic = new Inner();
864 ic.test();
865 }
866
testF()867 void testF()
868 {
869 class Inner
870 {
871 void test()
872 {
873 int a = 1;
874
875 void localFunction()
876 {
877 void anotherLocalFunction()
878 {
879 count += a;
880 if (count != 30)
881 testF();
882 assert(a == 1);
883 }
884
885 anotherLocalFunction();
886 }
887
888 localFunction();
889 }
890 }
891 scope ic = new Inner();
892 ic.test();
893 }
894
testG()895 void testG()
896 {
897 class Inner
898 {
899 void test()
900 {
901 void localFunction()
902 {
903 int a = 1;
904
905 void anotherLocalFunction()
906 {
907 count += a;
908 if (count != 35)
909 testG();
910 assert(a == 1);
911 }
912
913 anotherLocalFunction();
914 }
915
916 localFunction();
917 }
918 }
919 scope ic = new Inner();
920 ic.test();
921 }
922 }
923
test191()924 void test191()
925 {
926 scope oc = new C191();
927 oc.testA();
928 assert(oc.count == 5);
929
930 oc.testB();
931 assert(oc.count == 10);
932
933 oc.testC();
934 assert(oc.count == 15);
935
936 oc.testD();
937 assert(oc.count == 20);
938
939 oc.testE();
940 assert(oc.count == 25);
941
942 oc.testF();
943 assert(oc.count == 30);
944
945 oc.testG();
946 assert(oc.count == 35);
947 }
948
949 /******************************************/
950 // https://bugzilla.gdcproject.org/show_bug.cgi?id=194
951
test194(ref bool overflow)952 auto test194(ref bool overflow)
953 {
954 import core.checkedint;
955
956 return adds(1, 1, overflow);
957 }
958
959 /******************************************/
960 // https://bugzilla.gdcproject.org/show_bug.cgi?id=196
961
962 class C196
963 {
964 int a;
965 }
966
967 struct S196
968 {
969 int a;
970 }
971
test196()972 void test196()
973 {
974 __gshared c = new C196();
975 __gshared s = new S196(0);
976 c.a = 1;
977 s.a = 1;
978 }
979
980 /******************************************/
981 // https://bugzilla.gdcproject.org/show_bug.cgi?id=198
982
983 struct S198a
984 {
985 union
986 {
987 float[3] v;
988 struct
989 {
990 float x;
991 float y;
992 float z;
993 }
994 }
995
996 this(float x_, float y_, float z_)
997 {
998 x = x_;
999 y = y_;
1000 z = z_;
1001 }
1002
1003 ref S198a opOpAssign(string op)(S198a operand)
1004 if (op == "+")
1005 {
1006 x += operand.x;
1007 y += operand.y;
1008 z += operand.z;
1009 return this;
1010 }
1011 }
1012
1013 struct S198b
1014 {
1015 @property get()
1016 {
1017 union Buf
1018 {
1019 void[0] result;
1020 }
1021 const Buf buf = { };
1022 return buf.result;
1023 }
1024 }
1025
1026 struct S198c
1027 {
1028 @property get()
1029 {
1030 union Buf
1031 {
1032 TypeInfo info;
1033 void[0] result;
1034 }
1035 const Buf buf = { };
1036 return buf.result;
1037 }
1038 }
1039
1040
1041 auto test198()
1042 {
1043 S198a sum = S198a(0, 0, 0);
1044
1045 foreach(size_t v; 0 .. 3)
1046 sum += S198a(1, 2, 3);
1047
1048 assert(sum.v == [3, 6, 9]);
1049 }
1050
1051 /******************************************/
1052 // https://bugzilla.gdcproject.org/show_bug.cgi?id=200
1053
1054 void test200a(double x, double y)
1055 {
1056 const double y2 = x + 1.0;
1057 assert(y == y2);
1058 }
1059
1060 void test200()
1061 {
1062 const double x = .012;
1063 const double y = x + 1.0;
1064 test200a(x, y);
1065 }
1066
1067 /******************************************/
1068 // https://bugzilla.gdcproject.org/show_bug.cgi?id=210
1069
1070 struct S210
1071 {
1072 ubyte a;
1073 uint b;
1074 }
1075
1076 union U210
1077 {
1078 S210 a;
1079 uint b;
1080 }
1081
1082 S210 test210a()
1083 {
1084 S210 s = S210(1, 2);
1085 return s;
1086 }
1087
1088 S210[2] test210b()
1089 {
1090 S210[2] s = [S210(1, 2), S210(3, 4)];
1091 return s;
1092 }
1093
1094 U210 test210c()
1095 {
1096 U210 s = U210(S210(1, 2));
1097 return s;
1098 }
1099
1100 U210[2] test210d()
1101 {
1102 U210[2] s = [U210(S210(1, 2)), U210(S210(3, 4))];
1103 return s;
1104 }
1105
1106 void test210()
1107 {
1108 S210 a = S210(1, 2);
1109 assert(a == S210(1, 2));
1110 assert(a == test210a());
1111 assert(a != S210(2, 1));
1112
1113 S210[2] b = [S210(1, 2), S210(3, 4)];
1114 assert(b == [S210(1, 2), S210(3, 4)]);
1115 assert(b == test210b());
1116 assert(b != [S210(2, 1), S210(3, 4)]);
1117
1118 U210 c = U210(S210(1, 2));
1119 assert(c == U210(S210(1, 2)));
1120 assert(c == test210c());
1121 assert(c != U210(S210(2, 1)));
1122
1123 U210[2] d = [U210(S210(1, 2)), U210(S210(3, 4))];
1124 assert(d == [U210(S210(1, 2)), U210(S210(3, 4))]);
1125 assert(d == test210d());
1126 assert(d != [U210(S210(2, 1)), U210(S210(3, 4))]);
1127 }
1128
1129 /******************************************/
1130 // https://bugzilla.gdcproject.org/show_bug.cgi?id=240
1131
1132 void test240a(int a, int b)
1133 {
1134 assert(a == 0);
1135 assert(b == 0);
1136 }
1137
1138 void test240()
1139 {
1140 int a = 0;
1141 test240a(a, a++);
1142 assert(a == 1);
1143 }
1144
1145 /******************************************/
1146 // https://bugzilla.gdcproject.org/show_bug.cgi?id=242
1147
1148 struct S242
1149 {
1150 enum M = S242();
1151 int a = 42;
1152
1153 auto iter()
1154 {
1155 this.a = 24;
1156 return this;
1157 }
1158 }
1159
1160 S242 test242a()
1161 {
1162 return S242.M.iter;
1163 }
1164
1165 void test242()
1166 {
1167 assert(test242a() == S242(24));
1168 }
1169
1170 /******************************************/
1171 // https://bugzilla.gdcproject.org/show_bug.cgi?id=248
1172
1173 class C248b
1174 {
1175 bool isintegral()
1176 {
1177 return false;
1178 }
1179 }
1180
1181 class C248a
1182 {
1183 int count = 0;
1184
1185 C248b getMemtype()
1186 {
1187 count++;
1188 return new C248b();
1189 }
1190 }
1191
1192 class C248
1193 {
1194 C248a sym;
1195
1196 this()
1197 {
1198 this.sym = new C248a();
1199 }
1200
1201 bool isintegral()
1202 {
1203 return sym.getMemtype().isintegral();
1204 }
1205 }
1206
1207 void test248()
1208 {
1209 C248 e = new C248();
1210 e.isintegral();
1211 assert(e.sym.count == 1);
1212 }
1213
1214 /******************************************/
1215 // https://bugzilla.gdcproject.org/show_bug.cgi?id=250
1216
1217 void test250()
1218 {
1219 struct S
1220 {
1221 string data;
1222 }
1223
1224 auto a = S("hello");
1225 auto b = S("hello".dup);
1226
1227 assert(a.data == b.data);
1228 assert(a == b);
1229 assert([a] == [b]);
1230 }
1231
1232 /******************************************/
1233 // https://bugzilla.gdcproject.org/show_bug.cgi?id=253
1234
1235 interface A253
1236 {
1237 void test253(int[int]);
1238 }
1239
1240 interface C253 : A253
1241 {
1242 }
1243
1244 class D253 : B253, C253
1245 {
1246 }
1247
1248 /******************************************/
1249 // https://bugzilla.gdcproject.org/show_bug.cgi?id=273
1250
1251 class B273
1252 {
1253 B273[] members;
1254 }
1255
1256 class D273 : B273
1257 {
1258 }
1259
1260 void test273()
1261 {
1262 auto noPointers = ClassInfo.ClassFlags.noPointers;
1263 assert((B273.classinfo.m_flags & noPointers) == 0);
1264 assert((D273.classinfo.m_flags & noPointers) == 0);
1265 }
1266
1267 /******************************************/
1268 // https://bugzilla.gdcproject.org/show_bug.cgi?id=285
1269
1270 inout(char)[] test285a(inout(char)* s) @nogc @system pure nothrow
1271 {
1272 import core.stdc.string : strlen;
1273 return s ? s[0 .. strlen(s)] : null;
1274 }
1275
1276 void test285()
1277 {
1278 assert(test285a(null) == null);
1279 assert(test285a("foo") == "foo");
1280 }
1281
1282 /******************************************/
1283 // https://bugzilla.gdcproject.org/show_bug.cgi?id=286
1284
1285 void test286()
1286 {
1287 struct K286
1288 {
1289 int count;
1290 this(this)
1291 {
1292 count++;
1293 }
1294 }
1295
1296 struct S286
1297 {
1298 int data;
1299 this(K286 key)
1300 {
1301 data = key.count;
1302 }
1303 }
1304
1305 S286 getData(K286 key)
1306 {
1307 static S286[K286] getCache;
1308 auto p = key in getCache;
1309 if (p)
1310 return *p;
1311 return (getCache[key] = S286(key));
1312 }
1313
1314 auto s = getData(K286());
1315 if (s.data == 0)
1316 assert(0);
1317 }
1318
1319 /******************************************/
1320 // https://bugzilla.gdcproject.org/show_bug.cgi?id=309
1321
1322 void test309()
1323 {
1324 creal f1 = +0.0 + 0.0i;
1325 creal f2 = +0.0 - 0.0i;
1326 creal f3 = -0.0 + 0.0i;
1327 creal f4 = +0.0 + 0.0i;
1328
1329 assert(f1 !is f2);
1330 assert(f1 !is f3);
1331 assert(f2 !is f3);
1332 assert(f1 is f4);
1333
1334 assert(!(f1 is f2));
1335 assert(!(f1 is f3));
1336 assert(!(f2 is f3));
1337 assert(!(f1 !is f4));
1338
1339 struct CReal
1340 {
1341 creal value;
1342 }
1343
1344 CReal s1 = CReal(+0.0 + 0.0i);
1345 CReal s2 = CReal(+0.0 - 0.0i);
1346 CReal s3 = CReal(-0.0 + 0.0i);
1347 CReal s4 = CReal(+0.0 + 0.0i);
1348
1349 assert(s1 !is s2);
1350 assert(s1 !is s3);
1351 assert(s2 !is s3);
1352 assert(s1 is s4);
1353
1354 assert(!(s1 is s2));
1355 assert(!(s1 is s3));
1356 assert(!(s2 is s3));
1357 assert(!(s1 !is s4));
1358 }
1359
1360 /******************************************/
1361
1362 void main()
1363 {
1364 test4();
1365 test17();
1366 test35();
1367 test36();
1368 test43();
1369 test51();
1370 test57();
1371 test66();
1372 test115();
1373 test131();
1374 test133();
1375 test141();
1376 test179();
1377 test186();
1378 test187();
1379 test191();
1380 test196();
1381 test198();
1382 test200();
1383 test210();
1384 test240();
1385 test242();
1386 test248();
1387 test250();
1388 test273();
1389 test285();
1390 test286();
1391 test309();
1392
1393 printf("Success!\n");
1394 }
1395