1 // PERMUTE_ARGS: -unittest -O -release -inline -fPIC -g
2
3 import std.stdio;
4 import core.stdc.stdio;
5
6 /******************************************/
7
8 struct S
9 {
opStarS10 int opStar() { return 7; }
11 }
12
test1()13 void test1()
14 {
15 S s;
16
17 printf("%d\n", *s);
18 assert(*s == 7);
19 }
20
21 /******************************************/
22
test2()23 void test2()
24 {
25 double[1][2] bar;
26 bar[0][0] = 1.0;
27 bar[1][0] = 2.0;
28 foo2(bar);
29 }
30
foo2(T...)31 void foo2(T...)(T args)
32 {
33 foreach (arg; args[0 .. $])
34 {
35 //writeln(arg);
36 bar2!(typeof(arg))(&arg);
37 }
38 }
39
40
bar2(D)41 void bar2(D)(const(void)* arg)
42 {
43 D obj = *cast(D*) arg;
44 }
45
46 /***************************************************/
47
test3()48 void test3()
49 {
50 version (unittest)
51 {
52 printf("unittest!\n");
53 }
54 else
55 {
56 printf("no unittest!\n");
57 }
58
59 version (assert)
60 {
61 printf("assert!\n");
62 }
63 else
64 {
65 printf("no assert!\n");
66 }
67 }
68
69
70 /***************************************************/
71
test4()72 void test4()
73 {
74 immutable int maxi = 8;
75 int[][maxi] neighbors = [ cast(int[])[ ], [ 0 ], [ 0, 1], [ 0, 2], [1, 2], [1, 2, 3, 4],
76 [ 2, 3, 5], [ 4, 5, 6 ] ];
77 int[maxi] grid;
78
79 // neighbors[0].length = 0;
80
81 void place(int k, uint mask)
82 { if(k<maxi) {
83 for(uint m = 1, d = 1; d <= maxi; d++, m<<=1)
84 if(!(mask & m)) {
85 bool ok = true;
86 int dif;
87 foreach(nb; neighbors[k])
88 if((dif=grid[nb]-d)==1 || dif==-1) {
89 ok = false; break;
90 }
91 if(ok) {
92 grid[k] = d;
93 place(k+1, mask | m);
94 }
95 }
96 } else {
97 printf(" %d\n%d %d %d\n%d %d %d\n %d\n\n",
98 grid[0], grid[1], grid[2], grid[3], grid[4], grid[5], grid[6], grid[7]);
99 }
100 }
101 place(0, 0);
102 }
103
104
105 /***************************************************/
106
107 struct S5
108 {
109 enum S5 some_constant = {2};
110
111 int member;
112 }
113
test5()114 void test5()
115 {
116 }
117
118 /***************************************************/
119
120 struct S6
121 {
122 int a, b, c;
123 }
124
125 struct T6
126 {
127 S6 s;
128 int b = 7;
129
opDot()130 S6* opDot()
131 {
132 return &s;
133 }
134 }
135
test6()136 void test6()
137 {
138 T6 t;
139 t.a = 4;
140 t.b = 5;
141 t.c = 6;
142 assert(t.a == 4);
143 assert(t.b == 5);
144 assert(t.c == 6);
145 assert(t.s.b == 0);
146 assert(t.sizeof == 4*4);
147 assert(t.init.sizeof == 4*4);
148 }
149
150 /***************************************************/
151
152 struct S7
153 {
154 int a, b, c;
155 }
156
157 class C7
158 {
159 S7 s;
160 int b = 7;
161
opDot()162 S7* opDot()
163 {
164 return &s;
165 }
166 }
167
test7()168 void test7()
169 {
170 C7 t = new C7();
171 t.a = 4;
172 t.b = 5;
173 t.c = 6;
174 assert(t.a == 4);
175 assert(t.b == 5);
176 assert(t.c == 6);
177 assert(t.s.b == 0);
178 assert(t.sizeof == (void*).sizeof);
179 assert(t.init is null);
180 }
181
182 /***************************************************/
183
184 void foo8(int n1 = __LINE__ + 0, int n2 = __LINE__, string s = __FILE__)
185 {
186 assert(n1 < n2);
187 printf("n1 = %d, n2 = %d, s = %.*s\n", n1, n2, s.length, s.ptr);
188 }
189
test8()190 void test8()
191 {
192 foo8();
193 }
194
195 /***************************************************/
196
197 void foo9(int n1 = __LINE__ + 0, int n2 = __LINE__, string s = __FILE__)()
198 {
199 assert(n1 < n2);
200 printf("n1 = %d, n2 = %d, s = %.*s\n", n1, n2, s.length, s.ptr);
201 }
202
test9()203 void test9()
204 {
205 foo9();
206 }
207
208 /***************************************************/
209
foo10(char c)210 int foo10(char c) pure nothrow
211 {
212 return 1;
213 }
214
test10()215 void test10()
216 {
217 int function(char c) fp;
218 int function(char c) pure nothrow fq;
219
220 fp = &foo10;
221 fq = &foo10;
222 }
223
224 /***************************************************/
225
226 class Base11 {}
227 class Derived11 : Base11 {}
228 class MoreDerived11 : Derived11 {}
229
fun11(Base11)230 int fun11(Base11) { return 1; }
fun11(Derived11)231 int fun11(Derived11) { return 2; }
232
test11()233 void test11()
234 {
235 MoreDerived11 m;
236
237 auto i = fun11(m);
238 assert(i == 2);
239 }
240
241 /***************************************************/
242
243 interface ABC {};
244 interface AB: ABC {};
245 interface BC: ABC {};
246 interface AC: ABC {};
247 interface A: AB, AC {};
248 interface B: AB, BC {};
249 interface C: AC, BC {};
250
f12(AB ab)251 int f12(AB ab) { return 1; }
f12(ABC abc)252 int f12(ABC abc) { return 2; }
253
test12()254 void test12()
255 {
256 A a;
257 auto i = f12(a);
258 assert(i == 1);
259 }
260
261 /***************************************************/
262
Foo13(alias x)263 template Foo13(alias x)
264 {
265 enum bar = x + 1;
266 }
267
268 static assert(Foo13!(2+1).bar == 4);
269
Bar13(alias x)270 template Bar13(alias x)
271 {
272 enum bar = x;
273 }
274
275 static assert(Bar13!("abc").bar == "abc");
276
test13()277 void test13()
278 {
279 }
280
281 /***************************************************/
282
Foo14(alias a)283 template Foo14(alias a)
284 {
285 alias Bar14!(a) Foo14;
286 }
287
Bar14(alias a)288 int Bar14(alias a)()
289 {
290 return a.sizeof;
291 }
292
test14()293 void test14()
294 {
295 auto i = Foo14!("hello")();
296 printf("i = %d\n", i);
297 assert(i == "hello".sizeof);
298 i = Foo14!(1)();
299 printf("i = %d\n", i);
300 assert(i == 4);
301 }
302
303 /***************************************************/
304
foo15()305 auto foo15()(int x)
306 {
307 return 3 + x;
308 }
309
test15()310 void test15()
311 {
312
313 auto bar()(int x)
314 {
315 return 5 + x;
316 }
317
318 printf("%d\n", foo15(4));
319 printf("%d\n", bar(4));
320 }
321
322 /***************************************************/
323
foo16(int x)324 int foo16(int x) { return 1; }
foo16(ref int x)325 int foo16(ref int x) { return 2; }
326
test16()327 void test16()
328 {
329 int y;
330 auto i = foo16(y);
331 printf("i == %d\n", i);
332 assert(i == 2);
333 i = foo16(3);
334 assert(i == 1);
335 }
336
337 /***************************************************/
338
339 class A17 { }
340 class B17 : A17 { }
341 class C17 : B17 { }
342
foo17(A17,ref int x)343 int foo17(A17, ref int x) { return 1; }
foo17(B17,ref int x)344 int foo17(B17, ref int x) { return 2; }
345
test17()346 void test17()
347 {
348 C17 c;
349 int y;
350 auto i = foo17(c, y);
351 printf("i == %d\n", i);
352 assert(i == 2);
353 }
354
355 /***************************************************/
356
357 class C18
358 {
foo(int x)359 void foo(int x) { foo("abc"); }
foo(string s)360 void foo(string s) { } // this is hidden, but that's ok 'cuz no overlap
bar()361 void bar()
362 {
363 foo("abc");
364 }
365 }
366
367 class D18 : C18
368 {
foo(int x)369 override void foo(int x) { }
370 }
371
test18()372 void test18()
373 {
374 D18 d = new D18();
375 d.bar();
376 }
377
378 /***************************************************/
379
foo19(alias int a)380 int foo19(alias int a)() { return a; }
381
test19()382 void test19()
383 {
384 int y = 7;
385 auto i = foo19!(y)();
386 printf("i == %d\n", i);
387 assert(i == 7);
388
389 i = foo19!(4)();
390 printf("i == %d\n", i);
391 assert(i == 4);
392 }
393
394 /***************************************************/
395
396 template Foo20(int x) if (x & 1)
397 {
398 const int Foo20 = 6;
399 }
400
401 template Foo20(int x) if ((x & 1) == 0)
402 {
403 const int Foo20 = 7;
404 }
405
test20()406 void test20()
407 {
408 int i = Foo20!(3);
409 printf("%d\n", i);
410 assert(i == 6);
411 i = Foo20!(4);
412 printf("%d\n", i);
413 assert(i == 7);
414 }
415
416 /***************************************************/
417
418 template isArray21(T : U[], U)
419 {
420 static const isArray21 = 1;
421 }
422
isArray21(T)423 template isArray21(T)
424 {
425 static const isArray21 = 0;
426 }
427
428 int foo21(T)(T x) if (isArray21!(T))
429 {
430 return 1;
431 }
432
433 int foo21(T)(T x) if (!isArray21!(T))
434 {
435 return 2;
436 }
437
test21()438 void test21()
439 {
440 auto i = foo21(5);
441 assert(i == 2);
442 int[] a;
443 i = foo21(a);
444 assert(i == 1);
445 }
446
447 /***************************************************/
448
test22()449 void test22()
450 {
451 immutable uint x, y;
452 foreach (i; x .. y) {}
453 }
454
455 /***************************************************/
456
457 const bool foo23 = is(typeof(function void() { }));
458 const bar23 = is(typeof(function void() { }));
459
test23()460 void test23()
461 {
462 assert(foo23 == true);
463 assert(bar23 == true);
464 }
465
466 /***************************************************/
467
foo24(int i)468 ref int foo24(int i)
469 {
470 static int x;
471 x = i;
472 return x;
473 }
474
test24()475 void test24()
476 {
477 int x = foo24(3);
478 assert(x == 3);
479 }
480
481 /***************************************************/
482
foo25(int i)483 ref int foo25(int i)
484 {
485 static int x;
486 x = i;
487 return x;
488 }
489
bar25(ref int x)490 int bar25(ref int x)
491 {
492 return x + 1;
493 }
494
test25()495 void test25()
496 {
497 int x = bar25(foo25(3));
498 assert(x == 4);
499 }
500
501 /***************************************************/
502
503 static int x26;
504
foo26(int i)505 ref int foo26(int i)
506 {
507 x26 = i;
508 return x26;
509 }
510
test26()511 void test26()
512 {
513 int* p = &foo26(3);
514 assert(*p == 3);
515 }
516
517 /***************************************************/
518
519 static int x27 = 3;
520
foo27(int i)521 ref int foo27(int i)
522 {
523 return x27;
524 }
525
test27()526 void test27()
527 {
528 foo27(3) = 4;
529 assert(x27 == 4);
530 }
531
532 /***************************************************/
533
foo28(ref int x)534 ref int foo28(ref int x) { return x; }
535
test28()536 void test28()
537 {
538 int a;
539 foo28(a);
540 }
541
542 /***************************************************/
543
wyda(int[]a)544 void wyda(int[] a) { printf("aaa\n"); }
wyda(int[int]a)545 void wyda(int[int] a) { printf("bbb\n"); }
546
547 struct S29
548 {
549 int[] a;
550
wydaS29551 void wyda()
552 {
553 a.wyda;
554 a.wyda();
555 }
556 }
557
test29()558 void test29()
559 {
560 int[] a;
561 a.wyda;
562 int[5] b;
563 b.wyda;
564 int[int] c;
565 c.wyda;
566
567 S29 s;
568 s.wyda();
569 }
570
571 /***************************************************/
572
573 void foo30(D)(D arg) if (isIntegral!D)
574 {
575 }
576
S30(T)577 struct S30(T) { }
U30(int T)578 struct U30(int T) { }
579
580 alias int myint30;
581
test30()582 void test30()
583 {
584
585 S30!myint30 u;
586 S30!int s;
587 S30!(int) t = s;
588
589 // U30!3 v = s;
590 }
591
592 /***************************************************/
593
594 class A31
595 {
foo(int * p)596 void foo(int* p) { }
597 }
598
599 class B31 : A31
600 {
foo(scope int * p)601 override void foo(scope int* p) { }
602 }
603
test31()604 void test31()
605 {
606 }
607
608 /***************************************************/
609
bar32()610 void bar32() { }
611
foo32(int * p)612 nothrow void foo32(int* p)
613 {
614 //try { bar32(); } catch (Object o) { }
615 try { bar32(); } catch (Throwable o) { }
616 try { bar32(); } catch (Exception o) { }
617 }
618
test32()619 void test32()
620 { int i;
621
622 foo32(&i);
623 }
624
625 /***************************************************/
626
627 struct Integer
628 {
thisInteger629 this(int i)
630 {
631 this.i = i;
632 }
633
thisInteger634 this(long ii)
635 {
636 i = 3;
637 }
638
639 const int i;
640 }
641
test33()642 void test33()
643 {
644 }
645
646 /***************************************************/
647
test34()648 void test34()
649 {
650 alias uint Uint;
651 foreach(Uint u;1..10) {}
652 for(Uint u=1;u<10;u++) {}
653 }
654
655 /***************************************************/
656
foo35(bool condition,ref int lhs,ref int rhs)657 ref int foo35(bool condition, ref int lhs, ref int rhs)
658 {
659 if ( condition ) return lhs;
660 return rhs;
661 }
662
bar35()663 ref int bar35()(bool condition, ref int lhs, ref int rhs)
664 {
665 if ( condition ) return lhs;
666 return rhs;
667 }
668
test35()669 void test35()
670 {
671 int a = 10, b = 11;
672
673 foo35(a<b, a, b) = 42;
674 printf("a = %d and b = %d\n", a, b); // a = 42 and b = 11
675 assert(a == 42 && b == 11);
676
677 bar35(a<b, a, b) = 52;
678 printf("a = %d and b = %d\n", a, b);
679 assert(a == 42 && b == 52);
680 }
681
682 /***************************************************/
683
684 int foo36(T...)(T ts)
685 if (T.length > 1)
686 {
687 return T.length;
688 }
689
690 int foo36(T...)(T ts)
691 if (T.length <= 1)
692 {
693 return T.length * 7;
694 }
695
test36()696 void test36()
697 {
698 auto i = foo36!(int,int)(1, 2);
699 assert(i == 2);
700 i = foo36(1, 2, 3);
701 assert(i == 3);
702 i = foo36(1);
703 assert(i == 7);
704 i = foo36();
705 assert(i == 0);
706 }
707
708
709 /***************************************************/
710
test6685()711 void test6685()
712 {
713 struct S { int x; }
714 with({ return S(); }())
715 {
716 x++;
717 }
718 }
719
720 /***************************************************/
721
A37(alias T)722 struct A37(alias T)
723 {
724 }
725
726 void foo37(X)(X x) if (is(X Y == A37!(U), alias U))
727 {
728 }
729
bar37()730 void bar37() {}
731
test37()732 void test37()
733 {
734 A37!(bar37) a2;
735 foo37(a2);
736 foo37!(A37!bar37)(a2);
737 }
738
739 /***************************************************/
740
741 struct A38
742 {
thisA38743 this(this)
744 {
745 printf("B's copy\n");
746 }
emptyA38747 bool empty() {return false;}
popFrontA38748 void popFront() {}
frontA38749 int front() { return 1; }
750 // ref A38 opSlice() { return this; }
751 }
752
test38()753 void test38()
754 {
755 A38 a;
756 int i;
757 foreach (e; a) { if (++i == 100) break; }
758 }
759
760 /***************************************************/
761
762 alias int function() Fun39;
763 alias ref int function() Gun39;
764 static assert(!is(Fun39 == Gun39));
765
test39()766 void test39()
767 {
768 }
769
770 /***************************************************/
771
772 int x40;
773
774 struct Proxy
775 {
atProxy776 ref int at(int i)() { return x40; }
777 }
778
test40()779 void test40()
780 {
781 Proxy p;
782 auto x = p.at!(1);
783 }
784
785 /***************************************************/
786
Foo41(TList...)787 template Foo41(TList...)
788 {
789 alias TList Foo41;
790 }
791
792 alias Foo41!(immutable(ubyte)[], ubyte[]) X41;
793
test41()794 void test41()
795 {
796 }
797
798
799 /***************************************************/
800
endsWith(A1,A2)801 bool endsWith(A1, A2)(A1 longer, A2 shorter)
802 {
803 static if (is(typeof(longer[0 .. 0] == shorter)))
804 {
805 }
806 else
807 {
808 }
809 return false;
810 }
811
test42()812 void test42()
813 {
814 char[] a;
815 byte[] b;
816 endsWith(a, b);
817 }
818
819 /***************************************************/
820
821 void f43(S...)(S s) if (S.length > 3)
822 {
823 }
824
test43()825 void test43()
826 {
827 f43(1, 2, 3, 4);
828 }
829
830
831 /***************************************************/
832
833 struct S44(int x = 1){}
834
fun()835 void fun()(S44!(1) b) { }
836
test44()837 void test44()
838 {
839 S44!() s;
840 fun(s);
841 }
842
843 /***************************************************/
844 // 2006
845
test2006()846 void test2006()
847 {
848 string [][] aas = [];
849 assert(aas.length == 0);
850 aas ~= cast (string []) [];
851 assert(aas.length == 1);
852 aas = aas ~ cast (string []) [];
853 assert(aas.length == 2);
854 }
855
856 /***************************************************/
857 // 8442
858
test8442()859 void test8442()
860 {
861 enum int[] fooEnum = [];
862 immutable fooImmutable = fooEnum;
863 }
864
865 /***************************************************/
866
867 class A45
868 {
869 int x;
f()870 int f()
871 {
872 printf("A\n");
873 return 1;
874 }
875 }
876
877 class B45 : A45
878 {
f()879 override const int f()
880 {
881 printf("B\n");
882 return 2;
883 }
884 }
885
test45()886 void test45()
887 {
888 A45 y = new B45;
889 int i = y.f;
890 assert(i == 2);
891 }
892
893 /***************************************************/
894
text10682()895 void text10682()
896 {
897 ulong x = 1;
898 ulong y = 2 ^^ x;
899 }
900
901 /***************************************************/
902
903 struct Test46
904 {
905 int foo;
906 }
907
test46()908 void test46()
909 {
910 enum Test46 test = {};
911 enum q = test.foo;
912 }
913
914 /***************************************************/
915
double_sqr(int x)916 pure int double_sqr(int x) {
917 int y = x;
918 void do_sqr() { y *= y; }
919 do_sqr();
920 return y;
921 }
922
test47()923 void test47()
924 {
925 assert(double_sqr(10) == 100);
926 }
927
928 /***************************************************/
929
sort(alias less)930 void sort(alias less)(string[] r)
931 {
932 bool pred()
933 {
934 return less("a", "a");
935 }
936 .sort!(less)(r);
937 }
938
foo48()939 void foo48()
940 {
941 int[string] freqs;
942 string[] words;
943
944 sort!((a, b) { return freqs[a] > freqs[b]; })(words);
945 sort!((string a, string b) { return freqs[a] > freqs[b]; })(words);
946 //sort!(bool (a, b) { return freqs[a] > freqs[b]; })(words);
947 //sort!(function (a, b) { return freqs[a] > freqs[b]; })(words);
948 //sort!(function bool(a, b) { return freqs[a] > freqs[b]; })(words);
949 sort!(delegate bool(string a, string b) { return freqs[a] > freqs[b]; })(words);
950
951 }
952
test48()953 void test48()
954 {
955 }
956
957 /***************************************************/
958 // 6408
959
960 static assert(!is(typeof(string[0..1].init)));
961 static assert(is(typeof(string[].init) == string[]));
962 static assert(is(typeof(string[][].init) == string[][]));
963 static assert(is(typeof(string[][][].init) == string[][][]));
964
965 static assert(is(typeof(string[1].init) == string[1]));
966 static assert(is(typeof(string[1][1].init) == string[1][1]));
967 static assert(is(typeof(string[1][1][1].init) == string[1][1][1]));
968
969 static assert(is(typeof(string[string].init) == string[string]));
970 static assert(is(typeof(string[string][string].init) == string[string][string]));
971 static assert(is(typeof(string[string][string][string].init) == string[string][string][string]));
972
TT6408(T...)973 template TT6408(T...) { alias T TT6408; }
974 static assert(is(typeof(TT6408!(int, int)[].init) == TT6408!(int, int)));
975 static assert(is(typeof(TT6408!(int, int)[0..$].init) == TT6408!(int, int)));
976 static assert(is(typeof(TT6408!(int, int)[$-1].init) == int));
977
978 /***************************************************/
979 // 9409
980
TT9409(T...)981 template TT9409(T...) { alias T TT9409; }
982
idxTypes9409(Prefix...)983 template idxTypes9409(Prefix...)
984 {
985 TT9409!((Prefix[$-1])) idxTypes9409;
986 }
987
988 alias idxTypes9409!(int) Types9409;
989
990 /***************************************************/
991
992 struct S49
993 {
994 static void* p;
995
thisS49996 this( string name )
997 {
998 printf( "(ctor) &%.*s.x = %p\n", name.length, name.ptr, &x );
999 p = cast(void*)&x;
1000 }
1001
invariantS491002 invariant() {}
1003
1004 int x;
1005 }
1006
test49()1007 void test49()
1008 {
1009 auto s = new S49("s2");
1010
1011 printf( "&s2.x = %p\n", &s.x );
1012 assert(cast(void*)&s.x == S49.p);
1013 }
1014
1015 /***************************************************/
1016
1017 auto max50(Ts...)(Ts args)
1018 if (Ts.length >= 2
1019 && is(typeof(Ts[0].init > Ts[1].init ? Ts[1].init : Ts[0].init)))
1020 {
1021 static if (Ts.length == 2)
1022 return args[1] > args[0] ? args[1] : args[0];
1023 else
1024 return max50(max50(args[0], args[1]), args[2 .. $]);
1025 }
1026
test50()1027 void test50()
1028 {
1029 assert(max50(4, 5) == 5);
1030 assert(max50(2.2, 4.5) == 4.5);
1031 assert(max50("Little", "Big") == "Little");
1032
1033 assert(max50(4, 5.5) == 5.5);
1034 assert(max50(5.5, 4) == 5.5);
1035 }
1036
1037 /***************************************************/
1038
test51()1039 void test51()
1040 {
1041 static immutable int[2] array = [ 42 ];
1042 enum e = array[1];
1043 static immutable int[1] array2 = [ 0: 42 ];
1044 enum e2 = array2[0];
1045 assert(e == 0);
1046 assert(e2 == 42);
1047 }
1048
1049 /***************************************************/
1050
1051 enum ubyte[4] a52 = [5,6,7,8];
1052
test52()1053 void test52()
1054 {
1055 int x=3;
1056 assert(a52[x]==8);
1057 }
1058
1059 /***************************************************/
1060
test53()1061 void test53()
1062 {
1063 size_t func2(immutable(void)[] t)
1064 {
1065 return 0;
1066 }
1067 }
1068
1069 /***************************************************/
1070
foo54(void delegate (void[])dg)1071 void foo54(void delegate(void[]) dg) { }
1072
test54()1073 void test54()
1074 {
1075 void func(void[] t) pure { }
1076 foo54(&func);
1077
1078 // void func2(const(void)[] t) { }
1079 // foo54(&func2);
1080 }
1081
1082 /***************************************************/
1083
1084 class Foo55
1085 {
noop1()1086 synchronized void noop1() { }
noop2()1087 void noop2() shared { }
1088 }
1089
test55()1090 void test55()
1091 {
1092 auto foo = new shared(Foo55);
1093 foo.noop1();
1094 foo.noop2();
1095 }
1096
1097 /***************************************************/
1098
1099 enum float one56 = 1 * 1;
X56(float E)1100 template X56(float E) { int X56 = 2; }
1101 alias X56!(one56 * one56) Y56;
1102
test56()1103 void test56()
1104 {
1105 assert(Y56 == 2);
1106 }
1107
1108 /***************************************************/
1109
test57()1110 void test57()
1111 {
1112 alias shared(int) T;
1113 assert (is(T == shared));
1114 }
1115
1116 /***************************************************/
1117
1118 struct A58
1119 {
1120 int a,b;
1121 }
1122
test58()1123 void test58()
1124 {
1125 A58[2] rg=[{1,2},{5,6}];
1126 assert(rg[0].a == 1);
1127 assert(rg[0].b == 2);
1128 assert(rg[1].a == 5);
1129 assert(rg[1].b == 6);
1130 }
1131
1132 /***************************************************/
1133
1134 class A59 {
foo(int i)1135 const foo(int i) { return i; }
1136 }
1137
1138 /***************************************************/
1139
test60()1140 void test60()
1141 {
1142 enum real ONE = 1.0;
1143 real x;
1144 for (x=0.0; x<10.0; x+=ONE)
1145 printf("%Lg\n", x);
1146 printf("%Lg\n", x);
1147 assert(x == 10);
1148 }
1149
1150 /***************************************************/
1151
immutable(T)1152 pure immutable(T)[] fooPT(T)(immutable(T)[] x, immutable(T)[] y){
1153
1154 immutable(T)[] fooState;
1155
1156 immutable(T)[] bar(immutable(T)[] x){
1157 fooState = "hello ";
1158 return x ~ y;
1159 }
1160
1161 return fooState ~ bar(x);
1162
1163 }
1164
1165
test61()1166 void test61()
1167 {
1168 writeln(fooPT("p", "c"));
1169 }
1170
1171 /***************************************************/
1172
test9577()1173 void test9577()
1174 {
1175 static int function(int)[] foo = [x => x];
1176 foo[0](0);
1177 }
1178
1179 /***************************************************/
1180
foo62(int[3]a)1181 int[3] foo62(int[3] a)
1182 {
1183 a[1]++;
1184 return a;
1185 }
1186
test62()1187 void test62()
1188 {
1189 int[3] b;
1190 b[0] = 1;
1191 b[1] = 2;
1192 b[2] = 3;
1193 auto c = foo62(b);
1194 assert(b[0] == 1);
1195 assert(b[1] == 2);
1196 assert(b[2] == 3);
1197
1198 assert(c[0] == 1);
1199 assert(c[1] == 3);
1200 assert(c[2] == 3);
1201 }
1202
1203 /***************************************************/
1204
test3927()1205 void test3927()
1206 {
1207 int[] array;
1208 assert(array.length++ == 0);
1209 assert(array.length == 1);
1210 assert(array.length-- == 1);
1211 assert(array.length == 0);
1212 }
1213
1214 /***************************************************/
1215
test63()1216 void test63()
1217 {
1218 int[3] b;
1219 b[0] = 1;
1220 b[1] = 2;
1221 b[2] = 3;
1222 auto c = b;
1223 b[1]++;
1224 assert(b[0] == 1);
1225 assert(b[1] == 3);
1226 assert(b[2] == 3);
1227
1228 assert(c[0] == 1);
1229 assert(c[1] == 2);
1230 assert(c[2] == 3);
1231 }
1232
1233 /***************************************************/
1234
test64()1235 void test64()
1236 {
1237 int[3] b;
1238 b[0] = 1;
1239 b[1] = 2;
1240 b[2] = 3;
1241 int[3] c;
1242 c = b;
1243 b[1]++;
1244 assert(b[0] == 1);
1245 assert(b[1] == 3);
1246 assert(b[2] == 3);
1247
1248 assert(c[0] == 1);
1249 assert(c[1] == 2);
1250 assert(c[2] == 3);
1251 }
1252
1253 /***************************************************/
1254
foo65(int[2]a)1255 int[2] foo65(int[2] a)
1256 {
1257 a[1]++;
1258 return a;
1259 }
1260
test65()1261 void test65()
1262 {
1263 int[2] b;
1264 b[0] = 1;
1265 b[1] = 2;
1266 int[2] c = foo65(b);
1267 assert(b[0] == 1);
1268 assert(b[1] == 2);
1269
1270 assert(c[0] == 1);
1271 assert(c[1] == 3);
1272 }
1273
1274 /***************************************************/
1275
foo66(int[1]a)1276 int[1] foo66(int[1] a)
1277 {
1278 a[0]++;
1279 return a;
1280 }
1281
test66()1282 void test66()
1283 {
1284 int[1] b;
1285 b[0] = 1;
1286 int[1] c = foo66(b);
1287 assert(b[0] == 1);
1288 assert(c[0] == 2);
1289 }
1290
1291 /***************************************************/
1292
foo67(out int[2]a)1293 int[2] foo67(out int[2] a)
1294 {
1295 a[0] = 5;
1296 a[1] = 6;
1297 return a;
1298 }
1299
test67()1300 void test67()
1301 {
1302 int[2] b;
1303 b[0] = 1;
1304 b[1] = 2;
1305 int[2] c = foo67(b);
1306 assert(b[0] == 5);
1307 assert(b[1] == 6);
1308
1309 assert(c[0] == 5);
1310 assert(c[1] == 6);
1311 }
1312
1313 /***************************************************/
1314
test68()1315 void test68()
1316 {
1317 digestToString(cast(ubyte[16])x"c3fcd3d76192e4007dfb496cca67e13b");
1318 }
1319
digestToString(const ubyte[16]digest)1320 void digestToString(const ubyte[16] digest)
1321 {
1322 assert(digest[0] == 0xc3);
1323 assert(digest[15] == 0x3b);
1324 }
1325
1326 /***************************************************/
1327
test69()1328 void test69()
1329 {
1330 digestToString69(cast(ubyte[16])x"c3fcd3d76192e4007dfb496cca67e13b");
1331 }
1332
digestToString69(ref const ubyte[16]digest)1333 void digestToString69(ref const ubyte[16] digest)
1334 {
1335 assert(digest[0] == 0xc3);
1336 assert(digest[15] == 0x3b);
1337 }
1338
1339 /***************************************************/
1340
test70()1341 void test70()
1342 {
1343 digestToString70("1234567890123456");
1344 }
1345
digestToString70(ref const char[16]digest)1346 void digestToString70(ref const char[16] digest)
1347 {
1348 assert(digest[0] == '1');
1349 assert(digest[15] == '6');
1350 }
1351
1352 /***************************************************/
1353
foo71(out shared int o)1354 void foo71(out shared int o) {}
1355
1356 /***************************************************/
1357
1358 struct foo72
1359 {
barfoo721360 int bar() shared { return 1; }
1361 }
1362
test72()1363 void test72()
1364 {
1365 shared foo72 f;
1366 auto x = f.bar;
1367 }
1368
1369 /***************************************************/
1370
1371 class Foo73
1372 {
1373 static if (is(typeof(this) T : shared T))
1374 static assert(0);
1375 static if (is(typeof(this) U == shared U))
1376 static assert(0);
1377 static if (is(typeof(this) U == const U))
1378 static assert(0);
1379 static if (is(typeof(this) U == immutable U))
1380 static assert(0);
1381 static if (is(typeof(this) U == const shared U))
1382 static assert(0);
1383
1384 static assert(!is(int == const));
1385 static assert(!is(int == immutable));
1386 static assert(!is(int == shared));
1387
1388 static assert(is(int == int));
1389 static assert(is(const(int) == const));
1390 static assert(is(immutable(int) == immutable));
1391 static assert(is(shared(int) == shared));
1392 static assert(is(const(shared(int)) == shared));
1393 static assert(is(const(shared(int)) == const));
1394
1395 static assert(!is(const(shared(int)) == immutable));
1396 static assert(!is(const(int) == immutable));
1397 static assert(!is(const(int) == shared));
1398 static assert(!is(shared(int) == const));
1399 static assert(!is(shared(int) == immutable));
1400 static assert(!is(immutable(int) == const));
1401 static assert(!is(immutable(int) == shared));
1402 }
1403
1404 template Bar(T : T)
1405 {
1406 alias T Bar;
1407 }
1408
1409 template Barc(T : const(T))
1410 {
1411 alias T Barc;
1412 }
1413
1414 template Bari(T : immutable(T))
1415 {
1416 alias T Bari;
1417 }
1418
1419 template Bars(T : shared(T))
1420 {
1421 alias T Bars;
1422 }
1423
1424 template Barsc(T : shared(const(T)))
1425 {
1426 alias T Barsc;
1427 }
1428
1429
test73()1430 void test73()
1431 {
1432 auto f = new Foo73;
1433
1434 alias int T;
1435
1436 // 5*5 == 25 combinations, plus 2 for swapping const and shared
1437
1438 static assert(is(Bar!(T) == T));
1439 static assert(is(Bar!(const(T)) == const(T)));
1440 static assert(is(Bar!(immutable(T)) == immutable(T)));
1441 static assert(is(Bar!(shared(T)) == shared(T)));
1442 static assert(is(Bar!(shared(const(T))) == shared(const(T))));
1443
1444 static assert(is(Barc!(const(T)) == T));
1445 static assert(is(Bari!(immutable(T)) == T));
1446 static assert(is(Bars!(shared(T)) == T));
1447 static assert(is(Barsc!(shared(const(T))) == T));
1448
1449 static assert(is(Barc!(T) == T));
1450 static assert(is(Barc!(immutable(T)) == T));
1451 static assert(is(Barc!(const(shared(T))) == shared(T)));
1452 static assert(is(Barsc!(immutable(T)) == T));
1453
1454 static assert(is(Bars!(const(shared(T))) == const(T)));
1455 static assert(is(Barsc!(shared(T)) == T));
1456
1457 Bars!(shared(const(T))) b;
1458 pragma(msg, typeof(b));
1459
1460 static assert(is(Bars!(shared(const(T))) == const(T)));
1461 static assert(is(Barc!(shared(const(T))) == shared(T)));
1462
1463 static assert(!is(Bari!(T)));
1464 static assert(!is(Bari!(const(T))));
1465 static assert(!is(Bari!(shared(T))));
1466 static assert(!is(Bari!(const(shared(T)))));
1467
1468 static assert(is(Barc!(shared(T))));
1469
1470 static assert(!is(Bars!(T)));
1471 static assert(!is(Bars!(const(T))));
1472 static assert(!is(Bars!(immutable(T))));
1473 static assert(!is(Barsc!(T)));
1474 static assert(!is(Barsc!(const(T))));
1475 }
1476
1477 /***************************************************/
1478
1479 pure nothrow {
1480 alias void function(int) A74;
1481 }
1482
1483 alias void function(int) pure nothrow B74;
1484 alias pure nothrow void function(int) C74;
1485
test74()1486 void test74()
1487 {
1488 A74 a = null;
1489 B74 b = null;
1490 C74 c = null;
1491 a = b;
1492 a = c;
1493 }
1494
1495 /***************************************************/
1496
test9212()1497 void test9212()
1498 {
1499 int[int] aa;
1500 foreach (const key, const val; aa) {}
1501 foreach (size_t key, size_t val; aa) {}
1502 }
1503
1504 /***************************************************/
1505
1506 class A75
1507 {
raise(string s)1508 pure static void raise(string s)
1509 {
1510 throw new Exception(s);
1511 }
1512 }
1513
test75()1514 void test75()
1515 { int x = 0;
1516 try
1517 {
1518 A75.raise("a");
1519 } catch (Exception e)
1520 {
1521 x = 1;
1522 }
1523 assert(x == 1);
1524 }
1525
1526 /***************************************************/
1527
test76()1528 void test76()
1529 {
1530 int x, y;
1531 bool which;
1532 (which ? x : y) += 5;
1533 assert(y == 5);
1534 }
1535
1536 /***************************************************/
1537
test77()1538 void test77()
1539 {
1540 auto a = ["hello", "world"];
1541 pragma(msg, typeof(a));
1542 auto b = a;
1543 assert(a is b);
1544 assert(a == b);
1545 b = a.dup;
1546 assert(a == b);
1547 assert(a !is b);
1548 }
1549
1550 /***************************************************/
1551
test78()1552 void test78()
1553 {
1554 auto array = [0, 2, 4, 6, 8, 10];
1555 array = array[0 .. $ - 2]; // Right-shrink by two elements
1556 assert(array == [0, 2, 4, 6]);
1557 array = array[1 .. $]; // Left-shrink by one element
1558 assert(array == [2, 4, 6]);
1559 array = array[1 .. $ - 1]; // Shrink from both sides
1560 assert(array == [4]);
1561 }
1562
1563 /***************************************************/
1564
test79()1565 void test79()
1566 {
1567 auto a = [87, 40, 10];
1568 a ~= 42;
1569 assert(a == [87, 40, 10, 42]);
1570 a ~= [5, 17];
1571 assert(a == [87, 40, 10, 42, 5, 17]);
1572 }
1573
1574 /***************************************************/
1575
test6317()1576 void test6317()
1577 {
1578 int b = 12345;
1579 struct nested { int a; int fun() { return b; } }
1580 static assert(!__traits(compiles, { nested x = { 3, null }; }));
1581 nested g = { 7 };
1582 auto h = nested(7);
1583 assert(g.fun() == 12345);
1584 assert(h.fun() == 12345);
1585 }
1586
1587 /***************************************************/
1588
test80()1589 void test80()
1590 {
1591 auto array = new int[10];
1592 array.length += 1000;
1593 assert(array.length == 1010);
1594 array.length /= 10;
1595 assert(array.length == 101);
1596 array.length -= 1;
1597 assert(array.length == 100);
1598 array.length |= 1;
1599 assert(array.length == 101);
1600 array.length ^= 3;
1601 assert(array.length == 102);
1602 array.length &= 2;
1603 assert(array.length == 2);
1604 array.length *= 2;
1605 assert(array.length == 4);
1606 array.length <<= 1;
1607 assert(array.length == 8);
1608 array.length >>= 1;
1609 assert(array.length == 4);
1610 array.length >>>= 1;
1611 assert(array.length == 2);
1612 array.length %= 2;
1613 assert(array.length == 0);
1614
1615 int[]* foo()
1616 {
1617 static int x;
1618 x++;
1619 assert(x == 1);
1620 auto p = &array;
1621 return p;
1622 }
1623
1624 (*foo()).length += 2;
1625 assert(array.length == 2);
1626 }
1627
1628 /***************************************************/
1629
test81()1630 void test81()
1631 {
1632 int[3] a = [1, 2, 3];
1633 int[3] b = a;
1634 a[1] = 42;
1635 assert(b[1] == 2); // b is an independent copy of a
1636 int[3] fun(int[3] x, int[3] y) {
1637 // x and y are copies of the arguments
1638 x[0] = y[0] = 100;
1639 return x;
1640 }
1641 auto c = fun(a, b); // c has type int[3]
1642 assert(c == [100, 42, 3]);
1643 assert(b == [1, 2, 3]); // b is unaffected by fun
1644 }
1645
1646 /***************************************************/
1647
test82()1648 void test82()
1649 {
1650 auto a1 = [ "Jane":10.0, "Jack":20, "Bob":15 ];
1651 auto a2 = a1; // a1 and a2 refer to the same data
1652 a1["Bob"] = 100; // Changing a1
1653 assert(a2["Bob"] == 100); //is same as changing a2
1654 a2["Sam"] = 3.5; //and vice
1655 assert(a2["Sam"] == 3.5); // versa
1656 }
1657
1658 /***************************************************/
1659
test7942()1660 void test7942()
1661 {
1662 string a = "a";
1663 wstring b = "b";
1664 dstring c = "c";
1665
1666 a ~= "a"c;
1667 static assert(!is(typeof(a ~= "b"w)));
1668 static assert(!is(typeof(a ~= "c"d)));
1669 static assert(!is(typeof(b ~= "a"c)));
1670 b ~= "b"w;
1671 static assert(!is(typeof(b ~= "c"d)));
1672 static assert(!is(typeof(c ~= "a"c)));
1673 static assert(!is(typeof(c ~= "b"w)));
1674 c ~= "c"d;
1675
1676 assert(a == "aa");
1677 assert(b == "bb");
1678 assert(c == "cc");
1679 }
1680
1681 /***************************************************/
1682
bump(ref int x)1683 void bump(ref int x) { ++x; }
1684
test83()1685 void test83()
1686 {
1687 int x = 1;
1688 bump(x);
1689 assert(x == 2);
1690 }
1691
1692 /***************************************************/
1693
1694 interface Test4174
1695 {
func(T)1696 void func(T)() {}
1697 }
1698
1699 /***************************************************/
1700
1701 auto foo84 = [1, 2.4];
1702
test84()1703 void test84()
1704 {
1705 pragma(msg, typeof([1, 2.4]));
1706 static assert(is(typeof([1, 2.4]) == double[]));
1707
1708 pragma(msg, typeof(foo84));
1709 static assert(is(typeof(foo84) == double[]));
1710 }
1711
1712 /***************************************************/
1713
test85()1714 void test85()
1715 {
1716 dstring c = "V\u00E4rld";
1717 c = c ~ '!';
1718 assert(c == "V\u00E4rld!");
1719 c = '@' ~ c;
1720 assert(c == "@V\u00E4rld!");
1721
1722 wstring w = "V\u00E4rld";
1723 w = w ~ '!';
1724 assert(w == "V\u00E4rld!");
1725 w = '@' ~ w;
1726 assert(w == "@V\u00E4rld!");
1727
1728 string s = "V\u00E4rld";
1729 s = s ~ '!';
1730 assert(s == "V\u00E4rld!");
1731 s = '@' ~ s;
1732 assert(s == "@V\u00E4rld!");
1733 }
1734
1735 /***************************************************/
1736
test86()1737 void test86()
1738 {
1739 int[][] a = [ [1], [2,3], [4] ];
1740 int[][] w = [ [1, 2], [3], [4, 5], [] ];
1741 int[][] x = [ [], [1, 2], [3], [4, 5], [] ];
1742 }
1743
1744 /***************************************************/
1745
1746 // Bugzilla 3379
1747
1748 T1[] find(T1, T2)(T1[] longer, T2[] shorter)
1749 if (is(typeof(longer[0 .. 1] == shorter) : bool))
1750 {
1751 while (longer.length >= shorter.length) {
1752 if (longer[0 .. shorter.length] == shorter) break;
1753 longer = longer[1 .. $];
1754 }
1755 return longer;
1756 }
1757
1758 auto max(T...)(T a)
1759 if (T.length == 2
1760 && is(typeof(a[1] > a[0] ? a[1] : a[0]))
1761 || T.length > 2
1762 && is(typeof(max(max(a[0], a[1]), a[2 .. $])))) {
1763 static if (T.length == 2) {
1764 return a[1] > a[0] ? a[1] : a[0];
1765 } else {
1766 return max(max(a[0], a[1]), a[2 .. $]);
1767 }
1768 }
1769
1770 // Cases which would ICE or segfault
Bulldog(T)1771 struct Bulldog(T){
1772 static void cat(Frog)(Frog f) if (true)
1773 { }
1774 }
1775
mouse()1776 void mouse(){
1777 Bulldog!(int).cat(0);
1778 }
1779
test87()1780 void test87()
1781 {
1782 double[] d1 = [ 6.0, 1.5, 2.4, 3 ];
1783 double[] d2 = [ 1.5, 2.4 ];
1784 assert(find(d1, d2) == d1[1 .. $]);
1785 assert(find(d1, d2) == d1[1 .. $]); // Check for memory corruption
1786 assert(max(4, 5) == 5);
1787 assert(max(3, 4, 5) == 5);
1788 }
1789
1790 /***************************************************/
1791
test4284(alias v)1792 template test4284(alias v) { enum test4284 = v.length == 0; }
1793 static assert(test4284!(cast(string)null));
1794 static assert(test4284!(cast(string[])null));
1795
1796 /***************************************************/
1797
1798 struct S88
1799 {
opDispatchS881800 void opDispatch(string s, T)(T i)
1801 {
1802 printf("S.opDispatch('%.*s', %d)\n", s.length, s.ptr, i);
1803 }
1804 }
1805
1806 class C88
1807 {
opDispatch(string s)1808 void opDispatch(string s)(int i)
1809 {
1810 printf("C.opDispatch('%.*s', %d)\n", s.length, s.ptr, i);
1811 }
1812 }
1813
1814 struct D88
1815 {
opDispatchD881816 template opDispatch(string s)
1817 {
1818 enum int opDispatch = 8;
1819 }
1820 }
1821
test88()1822 void test88()
1823 {
1824 S88 s;
1825 s.opDispatch!("hello")(7);
1826 s.foo(7);
1827
1828 auto c = new C88();
1829 c.foo(8);
1830
1831 D88 d;
1832 printf("d.foo = %d\n", d.foo);
1833 assert(d.foo == 8);
1834 }
1835
1836 /***************************************************/
1837
test89()1838 void test89() {
1839 static struct X {
1840 int x;
1841 int bar() { return x; }
1842 }
1843 X s;
1844 printf("%d\n", s.sizeof);
1845 assert(s.sizeof == 4);
1846 }
1847
1848 /***************************************************/
1849
1850 struct S90
1851 {
opDispatchS901852 void opDispatch( string name, T... )( T values )
1853 {
1854 assert(values[0] == 3.14);
1855 }
1856 }
1857
test90()1858 void test90( )
1859 { S90 s;
1860 s.opDispatch!("foo")( 3.14 );
1861 s.foo( 3.14 );
1862 }
1863
1864 /***************************************************/
1865
A7439(int r,int c)1866 struct A7439(int r, int c)
1867 {
1868 alias r R;
1869 alias c C;
1870 alias float[R * C] Data;
1871 Data _data;
1872 alias _data this;
1873
1874 this(Data ar){ _data = ar; }
1875
1876 pure ref float opIndex(size_t rr, size_t cc){ return _data[cc + rr * C]; }
1877 }
1878
test7439()1879 void test7439()
1880 {
1881 A7439!(2, 2) a = A7439!(2, 2)([8, 3, 2, 9]);
1882 a[0,0] -= a[0,0] * 2.0;
1883 }
1884
1885 /***************************************************/
1886
1887 void foo91(uint line = __LINE__) { printf("%d\n", line); }
1888
test91()1889 void test91()
1890 {
1891 foo91();
1892 printf("%d\n", __LINE__);
1893 }
1894
1895 /***************************************************/
1896
fun13468(Object e,typeof (null)needle)1897 bool fun13468(Object e, typeof(null) needle)
1898 {
1899 return (e == needle);
1900 }
1901
test13468()1902 void test13468()
1903 {
1904 assert(fun13468(null, null));
1905 }
1906
1907 /***************************************************/
1908
foo92(ref int x)1909 auto ref foo92(ref int x) { return x; }
bar92(ref int x)1910 int bar92(ref int x) { return x; }
1911
test92()1912 void test92()
1913 {
1914 int x = 3;
1915 int i = bar92(foo92(x));
1916 assert(i == 3);
1917 }
1918
1919 /***************************************************/
1920
1921 struct Foo93
1922 {
fooFoo931923 public int foo() const
1924 {
1925 return 2;
1926 }
1927 }
1928
test93()1929 void test93()
1930 {
1931 const Foo93 bar = Foo93();
1932 enum bla = bar.foo();
1933 assert(bla == 2);
1934 }
1935
1936 /***************************************************/
1937
1938
1939 extern(C++) class C1687
1940 {
func()1941 void func() {}
1942 }
1943
test1687()1944 void test1687()
1945 {
1946 auto c = new C1687();
1947 assert(c.__vptr[0] == (&c.func).funcptr);
1948 }
1949
1950 /***************************************************/
1951
1952 struct Foo94
1953 {
1954 int x, y;
1955 real z;
1956 }
1957
makeFoo(const int x,const int y)1958 pure nothrow Foo94 makeFoo(const int x, const int y)
1959 {
1960 return Foo94(x, y, 3.0);
1961 }
1962
test94()1963 void test94()
1964 {
1965 auto f = makeFoo(1, 2);
1966 assert(f.x==1);
1967 assert(f.y==2);
1968 assert(f.z==3);
1969 }
1970
1971 /***************************************************/
1972
1973 struct T95
1974 {
thisT951975 @disable this(this)
1976 {
1977 }
1978 }
1979
1980 struct S95
1981 {
1982 T95 t;
1983 }
1984
foo95()1985 @disable void foo95() { }
1986
1987 struct T95A
1988 {
1989 @disable this(this);
1990 }
1991
1992 struct S95A
1993 {
1994 T95A t;
1995 }
1996
foo95A()1997 @disable void foo95A() { }
1998
test95()1999 void test95()
2000 {
2001 S95 s;
2002 S95 t;
2003 static assert(!__traits(compiles, t = s));
2004 static assert(!__traits(compiles, foo95()));
2005
2006 S95A u;
2007 S95A v;
2008 static assert(!__traits(compiles, v = u));
2009 static assert(!__traits(compiles, foo95A()));
2010 }
2011
2012 /***************************************************/
2013
S96(alias init)2014 struct S96(alias init)
2015 {
2016 int[] content = init;
2017 }
2018
test96()2019 void test96()
2020 {
2021 S96!([12, 3]) s1;
2022 S96!([1, 23]) s2;
2023 writeln(s1.content);
2024 writeln(s2.content);
2025 assert(!is(typeof(s1) == typeof(s2)));
2026 }
2027
2028 /***************************************************/
2029
2030 struct A97
2031 {
opEqualsA972032 const bool opEquals(ref const A97) { return true; }
2033 ref A97 opUnary(string op)() if (op == "++")
2034 {
2035 return this;
2036 }
2037 }
2038
test97()2039 void test97()
2040 {
2041 A97 a, b;
2042 foreach (e; a .. b) {
2043 }
2044 }
2045
2046 /***************************************************/
2047
test98()2048 void test98()
2049 {
2050 auto a = new int[2];
2051 // the name "length" should not pop up in an index expression
2052 static assert(!is(typeof(a[length - 1])));
2053 }
2054
2055 /***************************************************/
2056
2057 string s99;
2058
bar99(string i)2059 void bar99(string i)
2060 {
2061 }
2062
function(string)2063 void function(string) foo99(string i)
2064 {
2065 return &bar99;
2066 }
2067
test99()2068 void test99()
2069 {
2070 foo99 (s99 ~= "a") (s99 ~= "b");
2071 assert(s99 == "ab");
2072 }
2073
2074 /***************************************************/
2075 // 5081
2076
test5081()2077 void test5081()
2078 {
2079 static pure immutable(int[]) x1()
2080 {
2081 int[] a = new int[](10);
2082 return a;
2083 }
2084 static pure immutable(int[]) x2(int len)
2085 {
2086 int[] a = new int[](len);
2087 return a;
2088 }
2089 static pure immutable(int[]) x3(immutable(int[]) org)
2090 {
2091 int[] a = new int[](org.length);
2092 return a;
2093 }
2094
2095 immutable a1 = x1();
2096 immutable a2 = x2(10);
2097 immutable a3 = x3([1,2]);
2098
2099 static pure int[] y1()
2100 {
2101 return new int[](10);
2102 }
2103
2104 immutable b1 = y1();
2105 }
2106
2107 /***************************************************/
2108
test100()2109 void test100()
2110 {
2111 string s;
2112
2113 /* Testing order of evaluation */
2114 void delegate(string, string) fun(string) {
2115 s ~= "b";
2116 return delegate void(string x, string y) { s ~= "e"; };
2117 }
2118 fun(s ~= "a")(s ~= "c", s ~= "d");
2119 assert(s == "abcde", s);
2120 }
2121
2122 /***************************************************/
2123
test101()2124 void test101()
2125 {
2126 int[] d1 = [ 6, 1, 2 ];
2127 byte[] d2 = [ 6, 1, 2 ];
2128 assert(d1 == d2);
2129 d2 ~= [ 6, 1, 2 ];
2130 assert(d1 != d2);
2131 }
2132
2133 /***************************************************/
2134
2135
test5403()2136 void test5403()
2137 {
2138 struct S
2139 {
2140 static int front;
2141 enum back = "yes!";
2142 bool empty;
2143 void popAny() { empty = true; }
2144 alias popAny popFront;
2145 alias popAny popBack;
2146 }
2147 S.front = 7;
2148 foreach(int i; S()) assert(i == 7);
2149 S.front = 2;
2150 foreach(i; S()) assert(i == 2);
2151 foreach_reverse(i; S()) assert(i == "yes!");
2152 }
2153
2154 /***************************************************/
2155
2156 static assert([1,2,3] == [1.0,2,3]);
2157
2158 /***************************************************/
2159
transmogrify(uint)2160 int transmogrify(uint) { return 1; }
transmogrify(long)2161 int transmogrify(long) { return 2; }
2162
test103()2163 void test103()
2164 {
2165 assert(transmogrify(42) == 1);
2166 }
2167
2168 /***************************************************/
2169
foo104(int x)2170 int foo104(int x)
2171 {
2172 int* p = &(x += 1);
2173 return *p;
2174 }
2175
bar104(int * x)2176 int bar104(int *x)
2177 {
2178 int* p = &(*x += 1);
2179 return *p;
2180 }
2181
test104()2182 void test104()
2183 {
2184 auto i = foo104(1);
2185 assert(i == 2);
2186 i = bar104(&i);
2187 assert(i == 3);
2188 }
2189
2190 /***************************************************/
2191
bump105(ref int x)2192 ref int bump105(ref int x) { return ++x; }
2193
test105()2194 void test105()
2195 {
2196 int x = 1;
2197 bump105(bump105(x)); // two increments
2198 assert(x == 3);
2199 }
2200
2201 /***************************************************/
2202
genFactorials(int n)2203 pure int genFactorials(int n) {
2204 static pure int factorial(int n) {
2205 if (n==2) return 1;
2206 return factorial(2);
2207 }
2208 return factorial(n);
2209 }
2210
2211 /***************************************************/
2212
test107()2213 void test107()
2214 {
2215 int[6] a;
2216 writeln(a);
2217 writeln(a.init);
2218 assert(a.init == [0,0,0,0,0,0]);
2219 }
2220
2221 /***************************************************/
2222
2223 class A109 {}
2224
test109()2225 void test109()
2226 {
2227 immutable(A109) b;
2228 A109 c;
2229 auto z = true ? b : c;
2230 //writeln(typeof(z).stringof);
2231 static assert(is(typeof(z) == const(A109)));
2232 }
2233
2234 /***************************************************/
2235
Boo(T)2236 template Boo(T) {}
2237 struct Foo110(T, alias V = Boo!T)
2238 {
2239 pragma(msg, V.stringof);
2240 static const s = V.stringof;
2241 }
2242 alias Foo110!double B110;
2243 alias Foo110!int A110;
2244
2245 static assert(B110.s == "Boo!double");
2246 static assert(A110.s == "Boo!int");
2247
2248 /***************************************************/
2249
test11247()2250 int test11247()
2251 {
2252 static assert(is(byte[typeof(int.init).sizeof] == byte[4]));
2253 static assert(is(byte[typeof(return).sizeof] == byte[4]));
2254 return 0;
2255 }
2256
2257 /***************************************************/
2258
2259 // 3716
test111()2260 void test111()
2261 {
2262 auto k1 = true ? [1,2] : []; // OK
2263 auto k2 = true ? [[1,2]] : [[]];
2264 auto k3 = true ? [] : [[1,2]];
2265 auto k4 = true ? [[[]]] : [[[1,2]]];
2266 auto k5 = true ? [[[1,2]]] : [[[]]];
2267 auto k6 = true ? [] : [[[]]];
2268 static assert(!is(typeof(true ? [[[]]] : [[1,2]]))); // Must fail
2269 }
2270
2271 /***************************************************/
2272 // 658
2273
test658()2274 void test658()
2275 {
2276 struct S { int i; }
2277 class C { int i; }
2278
2279 S s;
2280 S* sp = &s;
2281 with (sp) i = 42;
2282 assert(s.i == 42);
2283 with (&s) i = 43;
2284 assert(s.i == 43);
2285
2286 C c = new C;
2287 C* cp = &c;
2288 with (cp) i = 42;
2289 assert(c.i == 42);
2290 with (&c) i = 43;
2291 assert(c.i == 43);
2292 }
2293
2294 /***************************************************/
2295
test3069()2296 void test3069()
2297 {
2298 ubyte id = 0;
2299 void[] v = [id] ~ [id];
2300 }
2301
2302 /***************************************************/
2303 // 4303
2304
2305 template foo112() if (__traits(compiles,undefined))
2306 {
2307 enum foo112 = false;
2308 }
2309
2310 template foo112() if (true)
2311 {
2312 enum foo112 = true;
2313 }
2314
2315 pragma(msg,__traits(compiles,foo112!()));
2316 static assert(__traits(compiles,foo112!()));
2317
2318 const bool bar112 = foo112!();
2319
2320
2321 /***************************************************/
2322
2323 struct File113
2324 {
thisFile1132325 this(int name) { }
2326
~thisFile1132327 ~this() { }
2328
opAssignFile1132329 void opAssign(File113 rhs) { }
2330
2331 struct ByLine
2332 {
2333 File113 file;
2334
thisFile113::ByLine2335 this(int) { }
2336
2337 }
2338
byLineFile1132339 ByLine byLine()
2340 {
2341 return ByLine(1);
2342 }
2343 }
2344
2345 auto filter113(File113.ByLine rs)
2346 {
2347 struct Filter
2348 {
2349 this(File113.ByLine r) { }
2350 }
2351
2352 return Filter(rs);
2353 }
2354
test113()2355 void test113()
2356 {
2357 auto f = File113(1);
2358 auto rx = f.byLine();
2359 auto file = filter113(rx);
2360 }
2361
2362 /***************************************************/
2363
foo114(fun...)2364 template foo114(fun...)
2365 {
2366 auto foo114(int[] args)
2367 {
2368 return 1;
2369 }
2370 }
2371
2372 pragma(msg, typeof(foo114!"a + b"([1,2,3])));
2373
2374 /***************************************************/
2375 // Bugzilla 3935
2376
2377 struct Foo115 {
opBinaryFoo1152378 void opBinary(string op)(Foo other) {
2379 pragma(msg, "op: " ~ op);
2380 assert(0);
2381 }
2382 }
2383
test115()2384 void test115()
2385 {
2386 Foo115 f;
2387 f = f;
2388 }
2389
2390 /***************************************************/
2391 // Bugzilla 2477
2392
2393 void foo116(T,)(T t) { T x; }
2394
test116()2395 void test116()
2396 {
2397 int[] data = [1,2,3,]; // OK
2398
2399 data = [ 1,2,3, ]; // fails
2400 auto i = data[1,];
2401 foo116!(int)(3);
2402 foo116!(int,)(3);
2403 foo116!(int,)(3,);
2404 }
2405
2406 /***************************************************/
2407
test1891()2408 void test1891()
2409 {
2410 struct C {
2411 char[8] x = "helloabc";
2412 }
2413
2414 int main()
2415 {
2416 C* a = new C;
2417 C*[] b;
2418 b ~= new C;
2419
2420 auto g = a ~ b;
2421 assert(g[0] && g[1] && g[0].x == g[1].x);
2422
2423 return 0;
2424 }
2425 }
2426
2427 /***************************************************/
2428 // Bugzilla 4291
2429
test117()2430 void test117() pure
2431 {
2432 mixin declareVariable;
2433 var = 42;
2434 mixin declareFunction;
2435 readVar();
2436 }
declareVariable()2437 template declareVariable() { int var; }
declareFunction()2438 template declareFunction()
2439 {
2440 int readVar() { return var; }
2441 }
2442
2443 /***************************************************/
2444 // Bugzilla 4177
2445
log118(real x)2446 pure real log118(real x) {
2447 if (__ctfe)
2448 return 0.0;
2449 else
2450 return 1.0;
2451 }
2452
2453 enum x118 = log118(4.0);
2454
test118()2455 void test118() {}
2456
2457 /***************************************************/
2458
bug4465()2459 void bug4465()
2460 {
2461 const a = 2 ^^ 2;
2462 int b = a;
2463 }
2464
2465 /***************************************************/
2466
foo(int * p)2467 pure void foo(int *p)
2468 {
2469 *p = 3;
2470 }
2471
test120()2472 pure void test120()
2473 {
2474 int i;
2475 foo(&i);
2476 assert(i == 3);
2477 }
2478
2479 /***************************************************/
2480 // 4866
2481
2482 immutable int[3] statik = [ 1, 2, 3 ];
2483 enum immutable(int)[] dynamic = statik;
2484
2485 static assert(is(typeof(dynamic) == immutable(int)[]));
2486 static if (! is(typeof(dynamic) == immutable(int)[]))
2487 {
2488 static assert(0); // (7)
2489 }
2490 pragma(msg, "!! ", typeof(dynamic));
2491
2492 /***************************************************/
2493 // 2943
2494
2495 struct Foo2943
2496 {
2497 int a;
2498 int b;
2499 alias b this;
2500 }
2501
test122()2502 void test122()
2503 {
2504 Foo2943 foo, foo2;
2505 foo.a = 1;
2506 foo.b = 2;
2507 foo2.a = 3;
2508 foo2.b = 4;
2509
2510 foo2 = foo;
2511 assert(foo2.a == foo.a);
2512 }
2513
2514 /***************************************************/
2515 // 4641
2516
2517 struct S123 {
2518 int i;
2519 alias i this;
2520 }
2521
test123()2522 void test123() {
2523 S123[int] ss;
2524 ss[0] = S123.init; // This line causes Range Violation.
2525 }
2526
2527 /***************************************************/
2528 // 2451
2529
2530 struct Foo124 {
2531 int z = 3;
opAssignFoo1242532 void opAssign(Foo124 x) { z= 2;}
2533 }
2534
2535 struct Bar124 {
2536 int z = 3;
this(this)2537 this(this){ z = 17; }
2538 }
2539
test124()2540 void test124() {
2541 Foo124[string] stuff;
2542 stuff["foo"] = Foo124.init;
2543 assert(stuff["foo"].z == 3);
2544 stuff["foo"] = Foo124.init;
2545 assert(stuff["foo"].z == 2);
2546
2547 Bar124[string] stuff2;
2548 Bar124 q;
2549 stuff2["dog"] = q;
2550 assert(stuff2["dog"].z == 17);
2551 }
2552
2553 /***************************************************/
2554
test3022()2555 void test3022()
2556 {
2557 static class Foo3022
2558 {
2559 new(size_t)
2560 {
2561 assert(0);
2562 }
2563 }
2564
2565 scope x = new Foo3022;
2566 }
2567
2568 /***************************************************/
2569
doNothing()2570 void doNothing() {}
2571
bug5071(short d,ref short c)2572 void bug5071(short d, ref short c) {
2573 assert(c==0x76);
2574
2575 void closure() {
2576 auto c2 = c;
2577 auto d2 = d;
2578 doNothing();
2579 }
2580 auto useless = &closure;
2581 }
2582
test125()2583 void test125()
2584 {
2585 short c = 0x76;
2586 bug5071(7, c);
2587 }
2588
2589 /***************************************************/
2590
2591 struct Foo126
2592 {
opCallFoo1262593 static Foo126 opCall(in Foo126 _f) pure
2594 {
2595 return _f;
2596 }
2597 }
2598
2599 /***************************************************/
2600
test796()2601 void test796()
2602 {
2603 struct S { invariant() { throw new Exception(""); } }
2604 S* s;
2605 try {
2606 assert(s);
2607 } catch (Error) {
2608 }
2609 }
2610
2611 /***************************************************/
2612
test7077()2613 void test7077()
2614 {
2615 if(0) mixin("auto x = 2;");
2616 auto x = 1;
2617 }
2618
2619 /***************************************************/
2620
Tuple127(S...)2621 struct Tuple127(S...)
2622 {
2623 S expand;
2624 alias expand this;
2625 }
2626
2627 alias Tuple127!(int, int) Foo127;
2628
test127()2629 void test127()
2630 {
2631 Foo127[] m_array;
2632 Foo127 f;
2633 m_array ~= f;
2634 }
2635
2636 /***************************************************/
2637
2638 struct Bug4434 {}
2639 alias const Bug4434* IceConst4434;
2640 alias shared Bug4434* IceShared4434;
2641 alias shared Bug4434[] IceSharedArray4434;
2642 alias immutable Bug4434* IceImmutable4434;
2643 alias shared const Bug4434* IceSharedConst4434;
2644
2645 alias int MyInt4434;
2646 alias const MyInt4434[3] IceConstInt4434;
2647
2648 alias immutable string[] Bug4830;
2649
2650 /***************************************************/
2651 // 4254
2652
bub(const inout int other)2653 void bub(const inout int other) {}
2654
test128()2655 void test128()
2656 {
2657 bub(1);
2658 }
2659
2660
2661 /***************************************************/
2662
bug4915a()2663 pure nothrow @safe auto bug4915a() { return 0; }
bug4915b()2664 pure nothrow @safe int bug4915b() { return bug4915a(); }
2665
bug4915c()2666 void bug4915c()
2667 {
2668 pure nothrow @safe int d() { return 0; }
2669 int e() pure nothrow @safe { return d(); }
2670 }
2671
2672 /***************************************************/
2673 // 5164
2674
2675 static if (is(int Q == int, Z...)) { }
2676
2677 /***************************************************/
2678 // 5195
2679
2680 alias typeof(foo5195) food5195;
2681 const int * foo5195 = null;
2682 alias typeof(foo5195) good5195;
2683 static assert( is (food5195 == good5195));
2684
2685 /***************************************************/
2686
version(Windows)2687 version (Windows)
2688 {
2689 }
2690 else
2691 {
2692 int[0] var5332;
test5332()2693 void test5332() { auto x = var5332; }
2694 }
2695
2696 /***************************************************/
2697 // 5191
2698
2699 struct Foo129
2700 {
addFoo1292701 void add(T)(T value) nothrow
2702 {
2703 this.value += value;
2704 }
2705
thisFoo1292706 this(int value)
2707 {
2708 this.value = value;
2709 }
2710
2711 int value;
2712 }
2713
test129()2714 void test129()
2715 {
2716 auto foo = Foo129(5);
2717 assert(foo.value == 5);
2718
2719 foo.add(2);
2720 writeln(foo.value);
2721 assert(foo.value == 7);
2722
2723 foo.add(3);
2724 writeln(foo.value);
2725 assert(foo.value == 10);
2726
2727 foo.add(3);
2728 writeln(foo.value);
2729 assert(foo.value == 13);
2730
2731 void delegate (int) nothrow dg = &foo.add!(int);
2732 dg(7);
2733 assert(foo.value == 20);
2734 }
2735
2736 /***************************************************/
2737 // 6169
2738
ctfefunc6169()2739 auto ctfefunc6169() { return "{}"; }
2740 enum ctfefptr6169 = &ctfefunc6169;
ctfefunc6169a()2741 int ctfefunc6169a() { return 1; }
x6169(string c)2742 template x6169(string c) { alias int x6169; }
TT6169(T...)2743 template TT6169(T...) { alias T TT6169; }
ctfeprop6169()2744 @property ctfeprop6169() { return "g"; }
2745
test6169()2746 void test6169() pure @safe
2747 {
2748 enum a = ctfefunc6169();
2749 static b = ctfefunc6169();
2750 x6169!(ctfefunc6169()) tt;
2751 mixin(ctfefunc6169());
2752 static if(ctfefunc6169()) {}
2753 pragma(msg, ctfefunc6169());
2754 enum xx
2755 {
2756 k = 0,
2757 j = ctfefunc6169a()
2758 }
2759 auto g = mixin('"' ~ ctfefunc6169() ~ '"');
2760 //auto h = import("testx.d" ~ false ? ctfefunc() : "");
2761 alias TT6169!(int, int)[ctfefunc6169a()..ctfefunc6169a()] i;
2762 alias TT6169!(int, int)[ctfefunc6169a()] j;
2763 int[ctfefunc6169a()+1] k;
2764 alias int[ctfefunc6169a()] l;
2765 switch(1)
2766 {
2767 //case ctfefunc6169a(): // Can't do this because of case variables
2768 case ctfefunc6169a()+1:
2769 ..
2770 case ctfefunc6169a()+2:
2771 default:
2772 break;
2773 }
2774 static assert(ctfefunc6169a());
2775 void fun(int i : ctfefunc6169a() = ctfefunc6169a(), alias j)() if (ctfefunc6169a()) {}
2776 fun!(ctfefunc6169a(), ctfefunc6169())();
2777 enum z = ctfefptr6169();
2778
2779 auto p = mixin(ctfeprop6169);
2780 }
2781
2782 /***************************************************/
2783 // 10506
2784
impureFunc10506()2785 void impureFunc10506() {}
join10506(RoR)2786 string join10506(RoR)(RoR ror)
2787 {
2788 impureFunc10506();
2789 return ror[0] ~ ror[1];
2790 }
2791
test10506()2792 void test10506() pure
2793 {
2794 void foobar() {}
2795
2796 mixin(["foo", "bar"].join10506()~";");
2797 }
2798
2799 /***************************************************/
2800
2801 const shared class C5107
2802 {
2803 int x;
2804 }
2805
2806 static assert(is(typeof(C5107.x) == const)); // okay
2807 static assert(is(typeof(C5107.x) == shared)); // fails!
2808
2809 /***************************************************/
2810
2811 immutable struct S3598
2812 {
funkcjaS35982813 static void funkcja() { }
2814 }
2815
2816 /***************************************************/
2817 // 4211
2818
2819 @safe struct X130
2820 {
func()2821 void func() { }
2822 }
2823
2824 @safe class Y130
2825 {
func()2826 void func() { }
2827 }
2828
test130()2829 @safe void test130()
2830 {
2831 X130 x;
2832 x.func();
2833 auto y = new Y130;
2834 y.func();
2835 }
2836
2837 /***************************************************/
2838
Return(alias fun)2839 template Return(alias fun)
2840 {
2841 static if (is(typeof(fun) R == return)) alias R Return;
2842 }
2843
2844 interface I4217
2845 {
2846 int square(int n);
2847 real square(real n);
2848 }
2849 alias Return!( __traits(getOverloads, I4217, "square")[0] ) R4217;
2850 alias Return!( __traits(getOverloads, I4217, "square")[1] ) S4217;
2851
2852 static assert(! is(R4217 == S4217));
2853
2854 /***************************************************/
2855 // 5094
2856
test131()2857 void test131()
2858 {
2859 S131 s;
2860 int[] conv = s;
2861 }
2862
2863 struct S131
2864 {
getS1312865 @property int[] get() { return [1,2,3]; }
2866 alias get this;
2867 }
2868
2869 /***************************************************/
2870
2871 struct S7545
2872 {
2873 uint id;
2874 alias id this;
2875 }
2876
test7545()2877 void test7545()
2878 {
2879 auto id = 0 ? S7545() : -1;
2880 }
2881
2882 /***************************************************/
2883 // 5020
2884
test132()2885 void test132()
2886 {
2887 S132 s;
2888 if (!s) {}
2889 }
2890
2891 struct S132
2892 {
2893 bool cond;
2894 alias cond this;
2895 }
2896
2897 /***************************************************/
2898 // 5343
2899
Tuple5343(Specs...)2900 struct Tuple5343(Specs...)
2901 {
2902 Specs[0] field;
2903 }
2904
S5343(E)2905 struct S5343(E)
2906 {
2907 immutable E x;
2908 }
2909 enum A5343{a,b,c}
2910 alias Tuple5343!(A5343) TA5343;
2911 alias S5343!(A5343) SA5343;
2912
2913 /***************************************************/
2914 // 5365
2915
2916 interface IFactory
2917 {
2918 void foo();
2919 }
2920
2921 class A133
2922 {
2923 protected static class Factory : IFactory
2924 {
foo()2925 void foo()
2926 {
2927 }
2928 }
2929
this()2930 this()
2931 {
2932 _factory = createFactory();
2933 }
2934
createFactory()2935 protected IFactory createFactory()
2936 {
2937 return new Factory;
2938 }
2939
2940 private IFactory _factory;
factory()2941 @property final IFactory factory()
2942 {
2943 return _factory;
2944 }
2945
2946 alias factory this;
2947 }
2948
test133()2949 void test133()
2950 {
2951
2952 IFactory f = new A133;
2953 f.foo(); // segfault
2954 }
2955
2956 /***************************************************/
2957 // 5365
2958
2959 class B134
2960 {
2961 }
2962
2963 class A134
2964 {
2965
2966 B134 _b;
2967
this()2968 this()
2969 {
2970 _b = new B134;
2971 }
2972
b()2973 B134 b()
2974 {
2975 return _b;
2976 }
2977
2978 alias b this;
2979 }
2980
test134()2981 void test134()
2982 {
2983
2984 auto a = new A134;
2985 B134 b = a; // b is null
2986 assert(a._b is b); // fails
2987 }
2988
2989 /***************************************************/
2990 // 5025
2991
2992 struct S135 {
2993 void delegate() d;
2994 }
2995
test135()2996 void test135()
2997 {
2998 shared S135[] s;
2999 if (0)
3000 s[0] = S135();
3001 }
3002
3003 /***************************************************/
3004 // 5545
3005
3006 bool enforce136(bool value, lazy const(char)[] msg = null) {
3007 if(!value) {
3008 return false;
3009 }
3010
3011 return value;
3012 }
3013
3014 struct Perm {
3015 byte[3] perm;
3016 ubyte i;
3017
thisPerm3018 this(byte[] input) {
3019 foreach(elem; input) {
3020 enforce136(i < 3);
3021 perm[i++] = elem;
3022 std.stdio.stderr.writeln(i); // Never gets incremented. Stays at 0.
3023 }
3024 }
3025 }
3026
test136()3027 void test136() {
3028 byte[] stuff = [0, 1, 2];
3029 auto perm2 = Perm(stuff);
3030 writeln(perm2.perm); // Prints [2, 0, 0]
3031 assert(perm2.perm[] == [0, 1, 2]);
3032 }
3033
3034 /***************************************************/
3035 // 4097
3036
foo4097()3037 void foo4097() { }
3038 alias typeof(&foo4097) T4097;
3039 static assert(is(T4097 X : X*) && is(X == function));
3040
3041 static assert(!is(X));
3042
3043 /***************************************************/
3044 // 5798
3045
assign9(ref int lhs)3046 void assign9(ref int lhs) pure {
3047 lhs = 9;
3048 }
3049
assign8(ref int rhs)3050 void assign8(ref int rhs) pure {
3051 rhs = 8;
3052 }
3053
test137()3054 int test137(){
3055 int a=1,b=2;
3056 assign8(b),assign9(a);
3057 assert(a == 9);
3058 assert(b == 8); // <-- fail
3059
3060 assign9(b),assign8(a);
3061 assert(a == 8);
3062 assert(b == 9); // <-- fail
3063
3064 return 0;
3065 }
3066
3067 /***************************************************/
3068
3069 // 9366
3070 static assert(!is(typeof((void[]).init ~ cast(void)0)));
3071 static assert(!is(typeof(cast(void)0 ~ (void[]).init)));
3072
3073 /***************************************************/
3074
3075 struct Size138
3076 {
3077 union
3078 {
3079 struct
3080 {
3081 int width;
3082 int height;
3083 }
3084
3085 long size;
3086 }
3087 }
3088
3089 enum Size138 foo138 = {2 ,5};
3090
3091 Size138 bar138 = foo138;
3092
3093 void test138()
3094 {
3095 assert(bar138.width == 2);
3096 assert(bar138.height == 5);
3097 }
3098
3099 /***************************************************/
3100
3101 void test3822()
3102 {
3103 import core.stdc.stdlib;
3104 int i = 0;
3105 void* ptr;
3106 while(i++ != 2)
3107 {
3108 auto p = alloca(2);
3109 assert(p != ptr);
3110 ptr = p;
3111 }
3112 }
3113
3114 /***************************************************/
3115
3116 // 5939, 5940
3117
3118 template map(fun...)
3119 {
3120 auto map(double[] r)
3121 {
3122 struct Result
3123 {
3124 this(double[] input)
3125 {
3126 }
3127 }
3128
3129 return Result(r);
3130 }
3131 }
3132
3133
3134 void test139()
3135 {
3136 double[] x;
3137 alias typeof(map!"a"(x)) T;
3138 T a = void;
3139 auto b = map!"a"(x);
3140 auto c = [map!"a"(x)];
3141 T[3] d = void;
3142 }
3143
3144
3145 /***************************************************/
3146 // 5966
3147
3148 string[] foo5966(string[] a)
3149 {
3150 a[0] = a[0][0..$];
3151 return a;
3152 }
3153
3154 enum var5966 = foo5966([""]);
3155
3156 /***************************************************/
3157 // 5975
3158
3159 int foo5975(wstring replace)
3160 {
3161 wstring value = "";
3162 value ~= replace;
3163 return 1;
3164 }
3165
3166 enum X5975 = foo5975("X"w);
3167
3168 /***************************************************/
3169 // 5965
3170
3171 template mapx(fun...) if (fun.length >= 1)
3172 {
3173 int mapx(Range)(Range r)
3174 {
3175 return 1;
3176 }
3177 }
3178
3179 void test140()
3180 {
3181 int foo(int i) { return i; }
3182
3183 int[] arr;
3184 auto x = mapx!( (int a){return foo(a);} )(arr);
3185 }
3186
3187 /***************************************************/
3188
3189 void bug5976()
3190 {
3191 int[] barr;
3192 int * k;
3193 foreach (ref b; barr)
3194 {
3195 scope(failure)
3196 k = &b;
3197 k = &b;
3198 }
3199 }
3200
3201 /***************************************************/
3202 // 5771
3203
3204 struct S141
3205 {
3206 this(A)(auto ref A a){}
3207 }
3208
3209 void test141()
3210 {
3211 S141 s = S141(10);
3212 }
3213
3214 /***************************************************/
3215
3216 class test5498_A {}
3217 class test5498_B : test5498_A {}
3218 class test5498_C : test5498_A {}
3219
3220 static assert(is(typeof([test5498_B.init, test5498_C.init]) == test5498_A[]));
3221
3222 /***************************************************/
3223 // 3688
3224
3225 struct S142
3226 {
3227 int v;
3228 this(int n) pure { v = n; }
3229 const bool opCast(T:bool)() { return true; }
3230 }
3231
3232 void test142()
3233 {
3234 if (int a = 1)
3235 assert(a == 1);
3236 else assert(0);
3237
3238 if (const int a = 2)
3239 assert(a == 2);
3240 else assert(0);
3241
3242 if (immutable int a = 3)
3243 assert(a == 3);
3244 else assert(0);
3245
3246 if (auto s = S142(10))
3247 assert(s.v == 10);
3248 else assert(0);
3249
3250 if (auto s = const(S142)(20))
3251 assert(s.v == 20);
3252 else assert(0);
3253
3254 if (auto s = immutable(S142)(30))
3255 assert(s.v == 30);
3256 else assert(0);
3257 }
3258
3259 /***************************************************/
3260 // 6072
3261
3262 static assert({
3263 if (int x = 5) {}
3264 return true;
3265 }());
3266
3267 /***************************************************/
3268 // 5959
3269
3270 int n;
3271
3272 void test143()
3273 {
3274 ref int f(){ return n; } // NG
3275 f() = 1;
3276 assert(n == 1);
3277
3278 nothrow ref int f1(){ return n; } // OK
3279 f1() = 2;
3280 assert(n == 2);
3281
3282 auto ref int f2(){ return n; } // OK
3283 f2() = 3;
3284 assert(n == 3);
3285 }
3286
3287 /***************************************************/
3288 // 6119
3289
3290 void startsWith(alias pred) () if (is(typeof(pred('c', 'd')) : bool))
3291 {
3292 }
3293
3294 void startsWith(alias pred) () if (is(typeof(pred('c', "abc")) : bool))
3295 {
3296 }
3297
3298 void test144()
3299 {
3300 startsWith!((a, b) { return a == b; })();
3301 }
3302
3303 /***************************************************/
3304
3305 void test145()
3306 {
3307 import core.stdc.stdio;
3308 printf("hello world 145\n");
3309 }
3310
3311 void test146()
3312 {
3313 test1();
3314 static import core.stdc.stdio;
3315 core.stdc.stdio.printf("hello world 146\n");
3316 }
3317
3318 /***************************************************/
3319 // 5856
3320
3321 struct X147
3322 {
3323 void f() { writeln("X.f mutable"); }
3324 void f() const { writeln("X.f const"); }
3325
3326 void g()() { writeln("X.g mutable"); }
3327 void g()() const { writeln("X.g const"); }
3328
3329 void opOpAssign(string op)(int n) { writeln("X+= mutable"); }
3330 void opOpAssign(string op)(int n) const { writeln("X+= const"); }
3331 }
3332
3333 void test147()
3334 {
3335 X147 xm;
3336 xm.f(); // prints "X.f mutable"
3337 xm.g(); // prints "X.g mutable"
3338 xm += 10; // should print "X+= mutable" (1)
3339
3340 const(X147) xc;
3341 xc.f(); // prints "X.f const"
3342 xc.g(); // prints "X.g const"
3343 xc += 10; // should print "X+= const" (2)
3344 }
3345
3346
3347 /***************************************************/
3348
3349 void test3559()
3350 {
3351 static class A
3352 {
3353 int foo(int a) { return 0; }
3354 int foo(float a) { return 1; }
3355
3356 int bar(float a) { return 1; }
3357 int bar(int a) { return 0; }
3358 }
3359
3360 static class B : A
3361 {
3362 override int foo(float a) { return 2; }
3363 alias A.foo foo;
3364
3365 alias A.bar bar;
3366 override int bar(float a) { return 2; }
3367 }
3368
3369 {
3370 auto x = new A;
3371 auto f1 = cast(int delegate(int))&x.foo;
3372 auto f2 = cast(int delegate(float))&x.foo;
3373 int delegate(int) f3 = &x.foo;
3374 int delegate(float) f4 = &x.foo;
3375
3376 assert(f1(0) == 0);
3377 assert(f2(0) == 1);
3378 assert(f3(0) == 0);
3379 assert(f4(0) == 1);
3380 }
3381
3382 {
3383 auto x = new B;
3384 auto f1 = cast(int delegate(int))&x.foo;
3385 auto f2 = cast(int delegate(float))&x.foo;
3386 int delegate(int) f3 = &x.foo;
3387 int delegate(float) f4 = &x.foo;
3388
3389 assert(f1(0) == 0);
3390 assert(f2(0) == 2);
3391 assert(f3(0) == 0);
3392 assert(f4(0) == 2);
3393 }
3394
3395 {
3396 auto x = new A;
3397 auto f1 = cast(int delegate(int))&x.bar;
3398 auto f2 = cast(int delegate(float))&x.bar;
3399 int delegate(int) f3 = &x.bar;
3400 int delegate(float) f4 = &x.bar;
3401
3402 assert(f1(0) == 0);
3403 assert(f2(0) == 1);
3404 assert(f3(0) == 0);
3405 assert(f4(0) == 1);
3406 }
3407
3408 {
3409 auto x = new B;
3410 auto f1 = cast(int delegate(int))&x.bar;
3411 auto f2 = cast(int delegate(float))&x.bar;
3412 int delegate(int) f3 = &x.bar;
3413 int delegate(float) f4 = &x.bar;
3414
3415 assert(f1(0) == 0);
3416 assert(f2(0) == 2);
3417 assert(f3(0) == 0);
3418 assert(f4(0) == 2);
3419 }
3420 }
3421
3422 /***************************************************/
3423
3424 extern(C++)
3425 class C13182
3426 {
3427 }
3428
3429 void test13182()
3430 {
3431 scope C13182 c = new C13182();
3432 }
3433
3434 /***************************************************/
3435 // 5897
3436
3437 struct A148{ int n; }
3438 struct B148{
3439 int n, m;
3440 this(A148 a){ n = a.n, m = a.n*2; }
3441 }
3442
3443 struct C148{
3444 int n, m;
3445 static C148 opCall(A148 a)
3446 {
3447 C148 b;
3448 b.n = a.n, b.m = a.n*2;
3449 return b;
3450 }
3451 }
3452
3453 void test148()
3454 {
3455 auto a = A148(10);
3456 auto b = cast(B148)a;
3457 assert(b.n == 10 && b.m == 20);
3458 auto c = cast(C148)a;
3459 assert(c.n == 10 && c.m == 20);
3460 }
3461
3462 /***************************************************/
3463 // 4969
3464
3465 class MyException : Exception
3466 {
3467 this()
3468 {
3469 super("An exception!");
3470 }
3471 }
3472
3473 void throwAway()
3474 {
3475 throw new MyException;
3476 }
3477
3478 void cantthrow() nothrow
3479 {
3480 try
3481 throwAway();
3482 catch(MyException me)
3483 assert(0);
3484 catch(Exception e)
3485 assert(0);
3486 }
3487
3488 /***************************************************/
3489 // 2356
3490
3491 void test2356()
3492 {
3493 int[3] x = [1,2,3];
3494 printf("x[] = [%d %d %d]\n", x[0], x[1], x[2]);
3495 assert(x[0] == 1 && x[1] == 2 && x[2] == 3);
3496
3497 struct S
3498 {
3499 static int pblit;
3500 int n;
3501 this(this) { ++pblit; printf("postblit: %d\n", n); }
3502 }
3503 S s2 = S(2);
3504 S[3] s = [S(1), s2, S(3)];
3505 assert(s[0].n == 1 && s[1].n == 2 && s[2].n == 3);
3506 printf("s[].n = [%d %d %d]\n", s[0].n, s[1].n, s[2].n);
3507 assert(S.pblit == 1);
3508
3509 ubyte[1024] v;
3510 v = typeof(v).init;
3511 printf("v[] = [%d %d %d, ..., %d]\n", v[0], v[1], v[2], v[$-1]);
3512 foreach (ref a; v) assert(a == 0);
3513
3514 int n = 5;
3515 int[3] y = [n, n, n];
3516 printf("y[] = [%d %d %d]\n", y[0], y[1], y[2]);
3517 assert(y[0] == 5 && y[1] == 5 && y[2] == 5);
3518
3519 S[3] z = [s2, s2, s2];
3520 assert(z[0].n == 2 && z[1].n == 2 && z[2].n == 2);
3521 printf("z[].n = [%d %d %d]\n", z[0].n, z[1].n, z[2].n);
3522 assert(S.pblit == 1 + 3);
3523
3524 int[0] nsa0 = [];
3525 void[0] vsa0 = [];
3526
3527 void foo(T)(T){}
3528 foo(vsa0);
3529
3530 ref int[0] bar() { static int[1] sa; return *cast(int[0]*)&sa; }
3531 bar() = [];
3532 }
3533
3534 /***************************************************/
3535 // 13652
3536
3537 void test13652()
3538 {
3539 // reduced case
3540 uint[9][5] arr =
3541 [[0, 0, 0, 0, 1, 5, 8, 0, 7],
3542 [0, 3, 8, 0, 2, 0, 0, 6, 0],
3543 [0, 0, 7, 0, 6, 8, 9, 4, 0],
3544 [0, 0, 0, 0, 0, 1, 2, 9, 0],
3545 [9, 7, 0, 0, 0, 0, 0, 8, 3]];
3546 assert(arr[0][0] == 0 && arr[0][1] == 0 && arr[0][2] == 0 &&
3547 arr[0][3] == 0 && arr[0][4] == 1 && arr[0][5] == 5 &&
3548 arr[0][6] == 8 && arr[0][7] == 0 && arr[0][8] == 7);
3549 assert(arr[1][0] == 0 && arr[1][1] == 3 && arr[1][2] == 8 &&
3550 arr[1][3] == 0 && arr[1][4] == 2 && arr[1][5] == 0 &&
3551 arr[1][6] == 0 && arr[1][7] == 6 && arr[1][8] == 0);
3552 assert(arr[2][0] == 0 && arr[2][1] == 0 && arr[2][2] == 7 &&
3553 arr[2][3] == 0 && arr[2][4] == 6 && arr[2][5] == 8 &&
3554 arr[2][6] == 9 && arr[2][7] == 4 && arr[2][8] == 0);
3555 assert(arr[3][0] == 0 && arr[3][1] == 0 && arr[3][2] == 0 &&
3556 arr[3][3] == 0 && arr[3][4] == 0 && arr[3][5] == 1 &&
3557 arr[3][6] == 2 && arr[3][7] == 9 && arr[3][8] == 0);
3558 assert(arr[4][0] == 9 && arr[4][1] == 7 && arr[4][2] == 0 &&
3559 arr[4][3] == 0 && arr[4][4] == 0 && arr[4][5] == 0 &&
3560 arr[4][6] == 0 && arr[4][7] == 8 && arr[4][8] == 3);
3561
3562 // original case
3563 uint[9][9] tbl =
3564 [[0, 0, 0, 0, 1, 5, 8, 0, 7],
3565 [0, 3, 8, 0, 2, 0, 0, 6, 0],
3566 [0, 0, 7, 0, 6, 8, 9, 4, 0],
3567 [0, 0, 0, 0, 0, 1, 2, 9, 0],
3568 [9, 7, 0, 0, 0, 0, 0, 8, 3],
3569 [0, 2, 1, 6, 0, 0, 0, 0, 0],
3570 [0, 6, 9, 5, 4, 0, 3, 0, 0],
3571 [0, 4, 0, 0, 8, 0, 6, 5, 0],
3572 [2, 0, 5, 9, 3, 0, 0, 0, 0]];
3573 assert(tbl[0][0] == 0 && tbl[0][1] == 0 && tbl[0][2] == 0 &&
3574 tbl[0][3] == 0 && tbl[0][4] == 1 && tbl[0][5] == 5 &&
3575 tbl[0][6] == 8 && tbl[0][7] == 0 && tbl[0][8] == 7);
3576 assert(tbl[1][0] == 0 && tbl[1][1] == 3 && tbl[1][2] == 8 &&
3577 tbl[1][3] == 0 && tbl[1][4] == 2 && tbl[1][5] == 0 &&
3578 tbl[1][6] == 0 && tbl[1][7] == 6 && tbl[1][8] == 0);
3579 assert(tbl[2][0] == 0 && tbl[2][1] == 0 && tbl[2][2] == 7 &&
3580 tbl[2][3] == 0 && tbl[2][4] == 6 && tbl[2][5] == 8 &&
3581 tbl[2][6] == 9 && tbl[2][7] == 4 && tbl[2][8] == 0);
3582 assert(tbl[3][0] == 0 && tbl[3][1] == 0 && tbl[3][2] == 0 &&
3583 tbl[3][3] == 0 && tbl[3][4] == 0 && tbl[3][5] == 1 &&
3584 tbl[3][6] == 2 && tbl[3][7] == 9 && tbl[3][8] == 0);
3585 assert(tbl[4][0] == 9 && tbl[4][1] == 7 && tbl[4][2] == 0 &&
3586 tbl[4][3] == 0 && tbl[4][4] == 0 && tbl[4][5] == 0 &&
3587 tbl[4][6] == 0 && tbl[4][7] == 8 && tbl[4][8] == 3);
3588 assert(tbl[5][0] == 0 && tbl[5][1] == 2 && tbl[5][2] == 1 &&
3589 tbl[5][3] == 6 && tbl[5][4] == 0 && tbl[5][5] == 0 &&
3590 tbl[5][6] == 0 && tbl[5][7] == 0 && tbl[5][8] == 0);
3591 assert(tbl[6][0] == 0 && tbl[6][1] == 6 && tbl[6][2] == 9 &&
3592 tbl[6][3] == 5 && tbl[6][4] == 4 && tbl[6][5] == 0 &&
3593 tbl[6][6] == 3 && tbl[6][7] == 0 && tbl[6][8] == 0);
3594 assert(tbl[7][0] == 0 && tbl[7][1] == 4 && tbl[7][2] == 0 &&
3595 tbl[7][3] == 0 && tbl[7][4] == 8 && tbl[7][5] == 0 &&
3596 tbl[7][6] == 6 && tbl[7][7] == 5 && tbl[7][8] == 0);
3597 assert(tbl[8][0] == 2 && tbl[8][1] == 0 && tbl[8][2] == 5 &&
3598 tbl[8][3] == 9 && tbl[8][4] == 3 && tbl[8][5] == 0 &&
3599 tbl[8][6] == 0 && tbl[8][6] == 0 && tbl[8][8] == 0);
3600 }
3601
3602 /***************************************************/
3603 // 11238
3604
3605 void test11238()
3606 {
3607 int[2] m;
3608 m[0] = 4,m[1] = 6;
3609 //printf("%d,%d\n", m[0], m[1]);
3610 assert(m[0] == 4 && m[1] == 6);
3611
3612 m = [m[1], m[0]]; // swap
3613 assert(m[0] == 6 && m[1] == 4);
3614 //printf("%d,%d\n", m[0], m[1]);
3615
3616 m = [m[1], m[0]]; // swap
3617 //printf("%d,%d\n", m[0], m[1]);
3618 assert(m[0] == 4 && m[1] == 6);
3619 }
3620
3621 /***************************************************/
3622
3623 void test11805()
3624 {
3625 int i;
3626
3627 i = 47;
3628 i = 1 && i;
3629 assert(i == 1);
3630 i = 0 || i;
3631 assert(i == 1);
3632 }
3633
3634 /***************************************************/
3635
3636 class A2540
3637 {
3638 int a;
3639 int foo() { return 0; }
3640 alias int X;
3641 }
3642
3643 class B2540 : A2540
3644 {
3645 int b;
3646 override super.X foo() { return 1; }
3647
3648 alias this athis;
3649 alias this.b thisb;
3650 alias super.a supera;
3651 alias super.foo superfoo;
3652 alias this.foo thisfoo;
3653 }
3654
3655 struct X2540
3656 {
3657 alias this athis;
3658 }
3659
3660 void test2540()
3661 {
3662 auto x = X2540.athis.init;
3663 static assert(is(typeof(x) == X2540));
3664
3665 B2540 b = new B2540();
3666
3667 assert(&b.a == &b.supera);
3668 assert(&b.b == &b.thisb);
3669 assert(b.thisfoo() == 1);
3670 }
3671
3672 /***************************************************/
3673
3674 class B14348
3675 {
3676 int foo() { return 0; }
3677 }
3678
3679 class C14348 : B14348
3680 {
3681 override int foo() { return 1; }
3682
3683 alias superfoo = typeof(super).foo;
3684 alias thisfoo = typeof(this).foo;
3685 }
3686
3687 B14348 test14348()
3688 {
3689 alias foo = typeof(return).foo; // currently doesn't work.
3690 assert(&B14348.foo is &C14348.superfoo);
3691 assert(&C14348.foo is &C14348.thisfoo);
3692 return null;
3693 }
3694
3695 /***************************************************/
3696 // 7295
3697
3698 struct S7295
3699 {
3700 int member;
3701 @property ref int refCountedPayload() { return member; }
3702 alias refCountedPayload this;
3703 }
3704
3705 void foo7295(S)(immutable S t, int qq) pure { }
3706 void foo7295(S)(S s) pure { }
3707
3708 void bar7295() pure
3709 {
3710 S7295 b;
3711 foo7295(b);
3712 }
3713
3714 /***************************************************/
3715 // 5659
3716
3717 void test149()
3718 {
3719 import std.traits;
3720
3721 char a;
3722 immutable(char) b;
3723
3724 static assert(is(typeof(true ? a : b) == const(char)));
3725 static assert(is(typeof([a, b][0]) == const(char)));
3726
3727 static assert(is(CommonType!(typeof(a), typeof(b)) == const(char)));
3728 }
3729
3730
3731 /***************************************************/
3732 // 1373
3733
3734 void func1373a(){}
3735
3736 static assert(typeof(func1373a).stringof == "void()");
3737 static assert(typeof(func1373a).mangleof == "FZv");
3738 static assert(!__traits(compiles, typeof(func1373a).alignof));
3739 static assert(!__traits(compiles, typeof(func1373a).init));
3740 static assert(!__traits(compiles, typeof(func1373a).offsetof));
3741
3742 void func1373b(int n){}
3743
3744 static assert(typeof(func1373b).stringof == "void(int n)");
3745 static assert(typeof(func1373b).mangleof == "FiZv");
3746 static assert(!__traits(compiles, typeof(func1373b).alignof));
3747 static assert(!__traits(compiles, typeof(func1373b).init));
3748 static assert(!__traits(compiles, typeof(func1373b).offsetof));
3749
3750 /***************************************************/
3751
3752 void bar150(T)(T n) { }
3753
3754 @safe void test150()
3755 {
3756 bar150(1);
3757 }
3758
3759 /***************************************************/
3760
3761 void test5785()
3762 {
3763 static struct x { static int y; }
3764 assert(x.y !is 1);
3765 assert(x.y !in [1:0]);
3766 }
3767
3768 /***************************************************/
3769
3770 void bar151(T)(T n) { }
3771
3772 nothrow void test151()
3773 {
3774 bar151(1);
3775 }
3776
3777 /***************************************************/
3778
3779 @property int coo() { return 1; }
3780 @property auto doo(int i) { return i; }
3781
3782 @property int eoo() { return 1; }
3783 @property auto ref hoo(int i) { return i; }
3784
3785 // 3359
3786
3787 int goo(int i) pure { return i; }
3788 auto ioo(int i) pure { return i; }
3789 auto ref boo(int i) pure nothrow { return i; }
3790
3791 class A152 {
3792 auto hoo(int i) pure { return i; }
3793 const boo(int i) nothrow { return i; }
3794 auto coo(int i) const { return i; }
3795 auto doo(int i) immutable { return i; }
3796 auto eoo(int i) shared { return i; }
3797 }
3798
3799 // 4706
3800
3801 struct Foo152(T) {
3802 @property auto ref front() {
3803 return T.init;
3804 }
3805
3806 @property void front(T num) {}
3807 }
3808
3809 void test152() {
3810 Foo152!int foo;
3811 auto a = foo.front;
3812 foo.front = 2;
3813 }
3814
3815 /***************************************************/
3816 // 6733
3817
3818 void bug6733(int a, int b) pure nothrow { }
3819 void test6733() {
3820 int z = 1;
3821 bug6733(z++, z++);
3822 assert(z==3);
3823 }
3824
3825 /***************************************************/
3826 // 3799
3827
3828 void test153()
3829 {
3830 void bar()
3831 {
3832 }
3833
3834 static assert(!__traits(isStaticFunction, bar));
3835 }
3836
3837 /***************************************************/
3838 // 3632
3839
3840
3841 void test154() {
3842 float f;
3843 assert(f is float.init);
3844 double d;
3845 assert(d is double.init);
3846 real r;
3847 assert(r is real.init);
3848
3849 assert(float.nan is float.nan);
3850 assert(double.nan is double.nan);
3851 assert(real.nan is real.nan);
3852 }
3853
3854 /***************************************************/
3855
3856 void test6545()
3857 {
3858 static int[] func()
3859 {
3860 auto a = [1, 2, 3];
3861 auto b = [2, 3, 4];
3862 auto c = [3, 4, 5];
3863
3864 a[] = b[] + c[];
3865
3866 return a;
3867 }
3868
3869 auto a = func();
3870 enum b = func();
3871 assert(a == b);
3872 }
3873
3874 /***************************************************/
3875 // 3147
3876
3877
3878 void test155()
3879 {
3880 byte b = 1;
3881 short s;
3882 int i;
3883 long l;
3884
3885 s = b + b;
3886 b = s % b;
3887 s = s >> b;
3888 b = 1;
3889 b = i % b;
3890 b = b >> i;
3891 }
3892
3893 /***************************************************/
3894 // 2486
3895
3896 void test2486()
3897 {
3898 void foo(ref int[] arr) {}
3899
3900 int[] arr = [1,2,3];
3901 foo(arr); //OK
3902 static assert(!__traits(compiles, foo(arr[1..2]))); // should be NG
3903
3904 struct S
3905 {
3906 int[] a;
3907 auto ref opSlice(){ return a[]; } // line 4
3908 }
3909 S s;
3910 s[];
3911 // opSlice should return rvalue
3912 static assert(is(typeof(&S.opSlice) == int[] function() pure nothrow @nogc @safe));
3913 static assert(!__traits(compiles, foo(s[]))); // should be NG
3914 }
3915
3916 /***************************************************/
3917
3918 extern(C++) class C15080
3919 {
3920 uint x = 1;
3921 uint y = 2;
3922 }
3923
3924 __gshared c15080 = new C15080();
3925
3926 void test15080()
3927 {
3928 assert(c15080.x == 1);
3929 assert(c15080.y == 2);
3930 }
3931
3932 /***************************************************/
3933 // 2521
3934
3935 immutable int val = 23;
3936 const int val2 = 23;
3937
3938 ref immutable(int) func2521_() {
3939 return val;
3940 }
3941 ref immutable(int) func2521_2() {
3942 return *&val;
3943 }
3944 ref immutable(int) func2521_3() {
3945 return func2521_;
3946 }
3947 ref const(int) func2521_4() {
3948 return val2;
3949 }
3950 ref const(int) func2521_5() {
3951 return val;
3952 }
3953 auto ref func2521_6() {
3954 return val;
3955 }
3956 ref func2521_7() {
3957 return val;
3958 }
3959
3960 /***************************************************/
3961
3962 void test5554()
3963 {
3964 class MA { }
3965 class MB : MA { }
3966 class MC : MB { }
3967
3968 class A { abstract MA foo(); }
3969 interface I { MB foo(); }
3970 class B : A
3971 {
3972 override MC foo() { return null; }
3973 }
3974 class C : B, I
3975 {
3976 override MC foo() { return null; }
3977 }
3978 }
3979
3980 /***************************************************/
3981 // 5962
3982
3983 struct S156
3984 {
3985 auto g()(){ return 1; }
3986 const auto g()(){ return 2; }
3987 }
3988
3989 void test156()
3990 {
3991 auto ms = S156();
3992 assert(ms.g() == 1);
3993 auto cs = const(S156)();
3994 assert(cs.g() == 2);
3995 }
3996
3997 /***************************************************/
3998
3999 void test10724()
4000 {
4001 const(char)* s = "abc"[0..$-1];
4002 assert(s[2] == '\0');
4003 }
4004
4005 /***************************************************/
4006
4007 void test6708(const ref int y)
4008 {
4009 immutable int x;
4010 test6708(x);
4011 }
4012
4013 /***************************************************/
4014 // 4258
4015
4016 struct Vec4258 {
4017 Vec4258 opOpAssign(string Op)(auto ref Vec4258 other) if (Op == "+") {
4018 return this;
4019 }
4020 Vec4258 opBinary(string Op:"+")(Vec4258 other) {
4021 Vec4258 result;
4022 return result += other;
4023 }
4024 }
4025 void test4258() {
4026 Vec4258 v;
4027 v += Vec4258() + Vec4258(); // line 12
4028 }
4029
4030 // regression fix test
4031
4032 struct Foo4258 {
4033 // binary ++/--
4034 int opPostInc()() if (false) { return 0; }
4035
4036 // binary 1st
4037 int opAdd(R)(R rhs) if (false) { return 0; }
4038 int opAdd_r(R)(R rhs) if (false) { return 0; }
4039
4040 // compare
4041 int opCmp(R)(R rhs) if (false) { return 0; }
4042
4043 // binary-op assign
4044 int opAddAssign(R)(R rhs) if (false) { return 0; }
4045 }
4046 struct Bar4258 {
4047 // binary commutive 1
4048 int opAdd_r(R)(R rhs) if (false) { return 0; }
4049
4050 // binary-op assign
4051 int opOpAssign(string op, R)(R rhs) if (false) { return 0; }
4052 }
4053 struct Baz4258 {
4054 // binary commutive 2
4055 int opAdd(R)(R rhs) if (false) { return 0; }
4056 }
4057 static assert(!is(typeof(Foo4258.init++)));
4058 static assert(!is(typeof(Foo4258.init + 1)));
4059 static assert(!is(typeof(1 + Foo4258.init)));
4060 static assert(!is(typeof(Foo4258.init < Foo4258.init)));
4061 static assert(!is(typeof(Foo4258.init += 1)));
4062 static assert(!is(typeof(Bar4258.init + 1)));
4063 static assert(!is(typeof(Bar4258.init += 1)));
4064 static assert(!is(typeof(1 + Baz4258.init)));
4065
4066 /***************************************************/
4067 // 4539
4068
4069 void test4539()
4070 {
4071 static assert(!__traits(compiles, "hello" = "red"));
4072
4073 void foo1(ref string s){}
4074 void foo2(ref const char[10] s){}
4075 void foo3(ref char[5] s){}
4076
4077 void foo4(ref const char[5] s)
4078 {
4079 assert(s[0] == 'h');
4080 assert(s[4] == 'o');
4081 }
4082 void foo5(ref const ubyte[5] s)
4083 {
4084 assert(s[0] == 0xc3);
4085 assert(s[4] == 0x61);
4086 }
4087
4088 static assert(!__traits(compiles, foo1("hello")));
4089 static assert(!__traits(compiles, foo2("hello")));
4090 static assert(!__traits(compiles, foo3("hello")));
4091
4092 // same as test68, 69, 70
4093 foo4("hello");
4094 foo5(cast(ubyte[5])x"c3fcd3d761");
4095
4096 //import std.conv;
4097 //static assert(!__traits(compiles, parse!int("10") == 10));
4098 }
4099
4100 /***************************************************/
4101 // 1471
4102
4103 void test1471()
4104 {
4105 int n;
4106 string bar = "BOOM"[n..$-1];
4107 assert(bar == "BOO");
4108 }
4109
4110 /***************************************************/
4111
4112 deprecated @disable int bug6389;
4113 static assert(!is(typeof(bug6389 = bug6389)));
4114
4115 /***************************************************/
4116
4117 void test10927()
4118 {
4119 static assert( (1+2i) ^^ 3 == -11 - 2i );
4120 auto a = (1+2i) ^^ 3;
4121 }
4122
4123 /***************************************************/
4124
4125 void test4963()
4126 {
4127 struct Value {
4128 byte a;
4129 }
4130 Value single()
4131 {
4132 return Value();
4133 }
4134
4135 Value[] list;
4136 auto x = single() ~ list;
4137 }
4138
4139 /***************************************************/
4140
4141 pure int test4031()
4142 {
4143 static const int x = 8;
4144 return x;
4145 }
4146
4147 /***************************************************/
4148 // 5437
4149
4150 template EnumMembers5437(E)
4151 {
4152 template TypeTuple(T...){ alias T TypeTuple; }
4153
4154 alias TypeTuple!("A", "B") EnumMembers5437;
4155 }
4156 template IntValue5437()
4157 {
4158 int IntValue5437 = 10;
4159 }
4160
4161 void test5437()
4162 {
4163 enum Foo { A, B }
4164 alias EnumMembers5437!Foo members; // OK
4165 enum n1 = members.length; // OK
4166 enum n2 = (EnumMembers5437!Foo).length; // NG, type -> symbol
4167
4168 enum s1 = IntValue5437!().sizeof; // OK
4169 enum s2 = (IntValue5437!()).sizeof; // NG, type -> expression
4170 }
4171
4172 /***************************************************/
4173 // 1962
4174
4175
4176 void test1962()
4177 {
4178 class C { abstract void x(); }
4179 assert(C.classinfo.create() is null);
4180 }
4181
4182 /***************************************************/
4183 // 6228
4184
4185
4186 void test6228()
4187 {
4188 const(int)* ptr;
4189 const(int) temp;
4190 auto x = (*ptr) ^^ temp;
4191 }
4192
4193 /***************************************************/
4194
4195 int test7544()
4196 {
4197 try { throw new Exception(""); }
4198 catch (Exception e) static assert(1);
4199 return 1;
4200 }
4201
4202 static assert(test7544());
4203
4204 /***************************************************/
4205
4206 struct S6230 {
4207 int p;
4208 int q() const pure {
4209 return p;
4210 }
4211 void r() pure {
4212 p = 231;
4213 }
4214 }
4215 class C6230 {
4216 int p;
4217 int q() const pure {
4218 return p;
4219 }
4220 void r() pure {
4221 p = 552;
4222 }
4223 }
4224 int q6230(ref const S6230 s) pure { // <-- Currently OK
4225 return s.p;
4226 }
4227 int q6230(ref const C6230 c) pure { // <-- Currently OK
4228 return c.p;
4229 }
4230 void r6230(ref S6230 s) pure {
4231 s.p = 244;
4232 }
4233 void r6230(ref C6230 c) pure {
4234 c.p = 156;
4235 }
4236 bool test6230pure() pure {
4237 auto s = S6230(4);
4238 assert(s.p == 4);
4239 assert(q6230(s) == 4);
4240 assert(s.q == 4);
4241
4242 auto c = new C6230;
4243 c.p = 6;
4244 assert(q6230(c) == 6);
4245 assert(c.q == 6);
4246
4247 r6230(s);
4248 assert(s.p == 244);
4249 s.r();
4250 assert(s.p == 231);
4251
4252 r6230(c);
4253 assert(c.p == 156);
4254 c.r();
4255 assert(c.p == 552);
4256
4257 return true;
4258 }
4259 void test6230() {
4260 assert(test6230pure());
4261 }
4262
4263 /***************************************************/
4264
4265 void test6264()
4266 {
4267 struct S { auto opSlice() { return this; } }
4268 int[] a;
4269 S s;
4270 static assert(!is(typeof(a[] = s[])));
4271 int*[] b;
4272 static assert(is(typeof(b[] = [new immutable(int)])));
4273 char[] c = new char[](5);
4274 c[] = "hello";
4275 }
4276
4277 /***************************************************/
4278 // 5046
4279
4280 void test5046()
4281 {
4282 auto va = S5046!("", int)();
4283 auto vb = makeS5046!("", int)();
4284 }
4285
4286 struct S5046(alias p, T)
4287 {
4288 T s;
4289 T fun() { return s; } // (10)
4290 }
4291
4292 S5046!(p, T) makeS5046(alias p, T)()
4293 {
4294 return typeof(return)();
4295 }
4296
4297 /***************************************************/
4298 // 6335
4299
4300 struct S6335
4301 {
4302 const int value;
4303 this()(int n){ value = n; }
4304 }
4305 void test6335()
4306 {
4307 S6335 s = S6335(10);
4308 }
4309
4310 /***************************************************/
4311
4312 struct S6295(int N) {
4313 int[N] x;
4314 const nothrow pure @safe f() { return x.length; }
4315 }
4316
4317 void test6295() {
4318 auto bar(T: S6295!(N), int N)(T x) {
4319 return x.f();
4320 }
4321 S6295!4 x;
4322 assert(bar(x) == 4);
4323 }
4324
4325 /***************************************************/
4326
4327 template TT4536(T...) { alias T TT4536; }
4328
4329 void test4536()
4330 {
4331 auto x = TT4536!(int, long, [1, 2]).init;
4332 assert(x[0] is int.init);
4333 assert(x[1] is long.init);
4334 assert(x[2] is [1, 2].init);
4335 }
4336
4337 /***************************************************/
4338
4339 struct S6284 {
4340 int a;
4341 }
4342 class C6284 {
4343 int a;
4344 }
4345 pure int bug6284a() {
4346 S6284 s = {4};
4347 auto b = s.a; // ok
4348 with (s) {
4349 b += a; // should be ok.
4350 }
4351 return b;
4352 }
4353 pure int bug6284b() {
4354 auto s = new S6284;
4355 s.a = 4;
4356 auto b = s.a;
4357 with (*s) {
4358 b += a;
4359 }
4360 return b;
4361 }
4362 pure int bug6284c() {
4363 auto s = new C6284;
4364 s.a = 4;
4365 auto b = s.a;
4366 with (s) {
4367 b += a;
4368 }
4369 return b;
4370 }
4371 void test6284() {
4372 assert(bug6284a() == 8);
4373 assert(bug6284b() == 8);
4374 assert(bug6284c() == 8);
4375 }
4376
4377 /***************************************************/
4378
4379 class C6293 {
4380 C6293 token;
4381 }
4382 void f6293(in C6293[] a) pure {
4383 auto x0 = a[0].token;
4384 assert(x0 is a[0].token.token.token);
4385 assert(x0 is (&x0).token);
4386 auto p1 = &x0 + 1;
4387 assert(x0 is (p1 - 1).token);
4388 int c = 0;
4389 assert(x0 is a[c].token);
4390 }
4391 void test6293() {
4392 auto x = new C6293;
4393 x.token = x;
4394 f6293([x]);
4395 }
4396
4397 /***************************************************/
4398 // 3733
4399
4400 class C3733
4401 {
4402 int foo() { return 1; }
4403 int foo() shared { return 2; }
4404
4405 int bar() { return foo(); }
4406 }
4407 void test3733()
4408 {
4409 auto c = new C3733();
4410 assert(c.bar() == 1);
4411 }
4412
4413 /***************************************************/
4414 // 4392
4415
4416 class C4392
4417 {
4418 int foo() const { return 1; }
4419 int foo() { return 2; }
4420
4421 int bar() const { return foo(); }
4422 }
4423 void test4392()
4424 {
4425 auto c = new C4392();
4426 assert(c.bar() == 1);
4427 }
4428
4429 /***************************************************/
4430 // 6220
4431
4432 void test6220() {
4433 struct Foobar { real x; real y; real z;}
4434 switch("x") {
4435 foreach(i,member; __traits(allMembers, Foobar)) {
4436 case member : break;
4437 }
4438 default : break;
4439 }
4440 }
4441
4442 /***************************************************/
4443 // 5799
4444
4445 void test5799()
4446 {
4447 int a;
4448 int *u = &(a ? a : (a ? a : a));
4449 assert(u == &a);
4450 }
4451
4452 /***************************************************/
4453 // 6529
4454
4455 enum Foo6529 : char { A='a' }
4456 ref const(Foo6529) func6529(const(Foo6529)[] arr){ return arr[0]; }
4457
4458 /***************************************************/
4459
4460 void test783()
4461 {
4462 const arr = [ 1,2,3 ];
4463 const i = 2;
4464 auto jhk = new int[arr[i]]; // "need size of rightmost array, not type arr[i]"
4465 }
4466
4467 /***************************************************/
4468
4469 template X157(alias x)
4470 {
4471 alias x X157;
4472 }
4473
4474 template Parent(alias foo)
4475 {
4476 alias X157!(__traits(parent, foo)) Parent;
4477 }
4478
4479 template ParameterTypeTuple(alias foo)
4480 {
4481 static if (is(typeof(foo) P == function))
4482 alias P ParameterTypeTuple;
4483 else
4484 static assert(0, "argument has no parameters");
4485 }
4486
4487 template Mfp(alias foo)
4488 {
4489 auto Mfp = function(Parent!foo self, ParameterTypeTuple!foo i) { return self.foo(i); };
4490 }
4491
4492 class C157 {
4493 int a = 3;
4494 int foo(int i, int y) { return i + a + y; }
4495 }
4496
4497 void test157()
4498 {
4499 auto c = new C157();
4500 auto mfp = Mfp!(C157.foo);
4501 auto i = mfp(c, 1, 7);
4502 assert(i == 11);
4503 }
4504
4505 /***************************************************/
4506 // 6473
4507
4508 struct Eins6473
4509 {
4510 ~this() {}
4511 }
4512
4513 struct Zwei6473
4514 {
4515 void build(Eins6473 devices = Eins6473())
4516 {
4517 }
4518 }
4519
4520 void build(Eins6473 devices = Eins6473())
4521 {}
4522
4523 void test6473()
4524 {
4525 void build(Eins6473 devices = Eins6473())
4526 {}
4527 }
4528
4529 /***************************************************/
4530
4531 uint rol11417(uint n)(in uint x)
4532 {
4533 return x << n | x >> 32 - n;
4534 }
4535
4536 uint ror11417(uint n)(in uint x)
4537 {
4538 return x >> n | x << 32 - n;
4539 }
4540
4541 void test11417()
4542 {
4543 assert(rol11417!1(0x8000_0000) == 0x1);
4544 assert(ror11417!1(0x1) == 0x8000_0000);
4545 }
4546
4547 /***************************************************/
4548
4549 void test6578()
4550 {
4551 static struct Foo
4552 {
4553 this(int x) pure {}
4554 }
4555 auto f1 = new const(Foo)(1);
4556 auto f2 = new immutable(Foo)(1);
4557 auto f3 = new shared(Foo)(1);
4558 auto f4 = const(Foo)(1);
4559 auto f5 = immutable(Foo)(1);
4560 auto f6 = shared(Foo)(1);
4561 static assert(is(typeof(f1) == const(Foo)*));
4562 static assert(is(typeof(f2) == immutable(Foo)*));
4563 static assert(is(typeof(f3) == shared(Foo)*));
4564 static assert(is(typeof(f4) == const(Foo)));
4565 static assert(is(typeof(f5) == immutable(Foo)));
4566 static assert(is(typeof(f6) == shared(Foo)));
4567
4568 static struct Bar
4569 {
4570 this(int x) const pure {}
4571 }
4572 auto g1 = new const(Bar)(1);
4573 auto g2 = new immutable(Bar)(1);
4574 auto g3 = new shared(Bar)(1);
4575 auto g4 = const(Bar)(1);
4576 auto g5 = immutable(Bar)(1);
4577 auto g6 = shared(Bar)(1);
4578 static assert(is(typeof(g1) == const(Bar)*));
4579 static assert(is(typeof(g2) == immutable(Bar)*));
4580 static assert(is(typeof(g3) == shared(Bar)*));
4581 static assert(is(typeof(g4) == const(Bar)));
4582 static assert(is(typeof(g5) == immutable(Bar)));
4583 static assert(is(typeof(g6) == shared(Bar)));
4584
4585 static struct Baz
4586 {
4587 this()(int x) const pure {}
4588 }
4589 auto h1 = new const(Baz)(1);
4590 auto h2 = new immutable(Baz)(1);
4591 auto h3 = new shared(const(Baz))(1);
4592 auto h4 = const(Baz)(1);
4593 auto h5 = immutable(Baz)(1);
4594 auto h6 = shared(const(Baz))(1);
4595 static assert(is(typeof(h1) == const(Baz)*));
4596 static assert(is(typeof(h2) == immutable(Baz)*));
4597 static assert(is(typeof(h3) == shared(const(Baz))*));
4598 static assert(is(typeof(h4) == const(Baz)));
4599 static assert(is(typeof(h5) == immutable(Baz)));
4600 static assert(is(typeof(h6) == shared(const(Baz))));
4601 }
4602
4603 /***************************************************/
4604 // 6630
4605
4606 void test6630()
4607 {
4608 static class B {}
4609
4610 static class A
4611 {
4612 this() { b = new B(); }
4613 B b;
4614 alias b this;
4615 }
4616
4617 void fun(A a)
4618 {
4619 a = null;
4620 assert(a is null);
4621 }
4622
4623 auto a = new A;
4624 assert(a.b !is null);
4625 fun(a);
4626 assert(a !is null);
4627 assert(a.b !is null);
4628 }
4629
4630 /***************************************************/
4631
4632 int i199 = 1;
4633
4634 void test199()
4635 {
4636 label:
4637 {
4638 int i199 = 2;
4639 }
4640 assert(i199 == 1);
4641 }
4642
4643 /***************************************************/
4644 // 6690
4645
4646 T useLazy6690(T)(lazy T val)
4647 {
4648 return val;
4649 // val is converted to delegate call, but it is typed as int delegate() - not @safe!
4650 }
4651 void test6690() @safe
4652 {
4653 useLazy6690(0);
4654 // Error: safe function 'test6690' cannot call system function 'useLazy6690'
4655 }
4656
4657 /***************************************************/
4658
4659 template Hoge6691()
4660 {
4661 immutable static int[int] dict;
4662 immutable static int value;
4663
4664 static this()
4665 {
4666 dict = [1:1, 2:2];
4667 value = 10;
4668 }
4669 }
4670 alias Hoge6691!() H6691;
4671
4672 /***************************************************/
4673
4674 void test10626()
4675 {
4676 double[2] v, x;
4677 struct Y { double u; }
4678 double z;
4679 Y y;
4680 double[2] r = v[] * x[0];
4681 //double[2] s = v[] * z++;
4682 //double[2] t = v[] * z--;
4683 double[2] a = v[] * ++z;
4684 double[2] b = v[] * --z;
4685 double[2] c = v[] * y.u;
4686 double[2] d = v[] * (x[] = 3, x[0]);
4687 double[2] e = v[] * (v[] ~ z)[0];
4688 }
4689
4690
4691 /***************************************************/
4692 // 2953
4693
4694 template Tuple2953(T...)
4695 {
4696 alias T Tuple2953;
4697 }
4698 template Range2953(int b)
4699 {
4700 alias Tuple2953!(1) Range2953;
4701 }
4702 void foo2953()()
4703 {
4704 Tuple2953!(int, int) args;
4705 foreach( x ; Range2953!(args.length) ){ }
4706 }
4707 void test2953()
4708 {
4709 foo2953!()();
4710 }
4711
4712 /***************************************************/
4713 // 2997
4714
4715 abstract class B2997 { void foo(); }
4716 interface I2997 { void bar(); }
4717 abstract class C2997 : B2997, I2997 {}
4718 //pragma(msg, __traits(allMembers, C).stringof);
4719
4720 void test2997()
4721 {
4722 enum ObjectMembers = ["toString","toHash","opCmp","opEquals","Monitor","factory"];
4723
4724 static assert([__traits(allMembers, C2997)] == ["foo"] ~ ObjectMembers ~ ["bar"]);
4725 }
4726
4727 /***************************************************/
4728 // 6596
4729
4730 extern (C) int function() pfunc6596;
4731 extern (C) int cfunc6596(){ return 0; }
4732 static assert(typeof(pfunc6596).stringof == "extern (C) int function()");
4733 static assert(typeof(cfunc6596).stringof == "extern (C) int()");
4734
4735
4736 /***************************************************/
4737 // 4423
4738
4739 struct S4423
4740 {
4741 this(string phrase, int num)
4742 {
4743 this.phrase = phrase;
4744 this.num = num;
4745 }
4746
4747 int opCmp(const ref S4423 rhs)
4748 {
4749 if (phrase < rhs.phrase)
4750 return -1;
4751 else if (phrase > rhs.phrase)
4752 return 1;
4753
4754 if (num < rhs.num)
4755 return -1;
4756 else if (num > rhs.num)
4757 return 1;
4758
4759 return 0;
4760 }
4761
4762 string phrase;
4763 int num;
4764 }
4765
4766 enum E4423 : S4423
4767 {
4768 a = S4423("hello", 1),
4769 b = S4423("goodbye", 45),
4770 c = S4423("world", 22),
4771 };
4772
4773 void test4423()
4774 {
4775 E4423 e;
4776 assert(e.phrase == "hello");
4777
4778 e = E4423.b;
4779 assert(e.phrase == "goodbye");
4780 }
4781
4782 /***************************************************/
4783 // 4647
4784
4785 interface Timer
4786 {
4787 final int run() { printf("Timer.run()\n"); fun(); return 1; };
4788 int fun();
4789 }
4790
4791 interface Application
4792 {
4793 final int run() { printf("Application.run()\n"); fun(); return 2; };
4794 int fun();
4795 }
4796
4797 class TimedApp : Timer, Application
4798 {
4799 int funCalls;
4800 override int fun()
4801 {
4802 printf("TimedApp.fun()\n");
4803 funCalls++;
4804 return 2;
4805 }
4806 }
4807
4808 class SubTimedApp : TimedApp
4809 {
4810 int subFunCalls;
4811
4812 override int fun()
4813 {
4814 printf("SubTimedApp.fun()\n");
4815 subFunCalls++;
4816 return 1;
4817 }
4818 }
4819
4820 void test4647()
4821 {
4822 //Test access to TimedApps base interfaces
4823 auto app = new TimedApp();
4824 assert((cast(Application)app).run() == 2);
4825 assert((cast(Timer)app).run() == 1);
4826 assert(app.Timer.run() == 1); // error, no Timer property
4827 assert(app.Application.run() == 2); // error, no Application property
4828 assert(app.run() == 1); // This would call Timer.run() if the two calls
4829 // above were commented out
4830 assert(app.funCalls == 5);
4831
4832 assert(app.TimedApp.fun() == 2);
4833 assert(app.funCalls == 6);
4834
4835 //Test direct access to SubTimedApp interfaces
4836 auto app2 = new SubTimedApp();
4837 assert((cast(Application)app2).run() == 2);
4838 assert((cast(Timer)app2).run() == 1);
4839 assert(app2.Application.run() == 2);
4840 assert(app2.Timer.run() == 1);
4841 assert(app2.funCalls == 0);
4842 assert(app2.subFunCalls == 4);
4843
4844 assert(app2.fun() == 1);
4845 assert(app2.SubTimedApp.fun() == 1);
4846 assert(app2.funCalls == 0);
4847 assert(app2.subFunCalls == 6);
4848
4849 //Test access to SubTimedApp interfaces via TimedApp
4850 auto app3 = new SubTimedApp();
4851 (cast(Timer)cast(TimedApp)app3).run();
4852 app3.TimedApp.Timer.run();
4853 assert((cast(Application)cast(TimedApp)app3).run() == 2);
4854 assert((cast(Timer)cast(TimedApp)app3).run() == 1);
4855 assert(app3.TimedApp.Application.run() == 2);
4856 assert(app3.TimedApp.Timer.run() == 1);
4857 assert(app3.funCalls == 0);
4858 assert(app3.subFunCalls == 6);
4859 }
4860
4861 /***************************************************/
4862
4863 template T1064(E...) { alias E T1064; }
4864
4865 int[] var1064 = [ T1064!(T1064!(T1064!(1, 2), T1064!(), T1064!(3)), T1064!(4, T1064!(T1064!(T1064!(T1064!(5)))), T1064!(T1064!(T1064!(T1064!())))),6) ];
4866
4867 void test1064()
4868 {
4869 assert(var1064 == [1,2,3,4,5,6]);
4870 }
4871
4872 /***************************************************/
4873 // 5696
4874
4875 template Seq5696(T...){ alias T Seq5696; }
4876 template Pred5696(T) { alias T Pred5696; } // TOKtemplate
4877 template Scope5696(int n){ template X(T) { alias T X; } } // TOKimport
4878 T foo5696(T)(T x) { return x; }
4879 void test5696()
4880 {
4881 foreach (pred; Seq5696!(Pred5696, Pred5696))
4882 {
4883 static assert(is(pred!int == int));
4884 }
4885
4886 foreach (scop; Seq5696!(Scope5696!0, Scope5696!1))
4887 {
4888 static assert(is(scop.X!int == int));
4889 }
4890
4891 alias Seq5696!(foo5696, foo5696) funcs;
4892 assert(funcs[0](0) == 0);
4893 assert(funcs[1](1) == 1);
4894 foreach (i, fn; funcs)
4895 {
4896 assert(fn(i) == i);
4897 }
4898 }
4899
4900 /***************************************************/
4901 // 5933
4902
4903 int dummyfunc5933();
4904 alias typeof(dummyfunc5933) FuncType5933;
4905
4906 struct S5933a { auto x() { return 0; } }
4907 static assert(is(typeof(&S5933a.init.x) == int delegate() pure nothrow @nogc @safe));
4908
4909 struct S5933b { auto x() { return 0; } }
4910 //static assert(is(typeof(S5933b.init.x) == FuncType5933));
4911
4912 struct S5933c { auto x() { return 0; } }
4913 static assert(is(typeof(&S5933c.x) == int function()));
4914
4915 struct S5933d { auto x() { return 0; } }
4916 static assert(is(typeof(S5933d.x) == FuncType5933));
4917
4918
4919 class C5933a { auto x() { return 0; } }
4920 static assert(is(typeof(&(new C5933b()).x) == int delegate()));
4921
4922 class C5933b { auto x() { return 0; } }
4923 //static assert(is(typeof((new C5933b()).x) == FuncType5933));
4924
4925 class C5933c { auto x() { return 0; } }
4926 static assert(is(typeof(&C5933c.x) == int function()));
4927
4928 class C5933d { auto x() { return 0; } }
4929 static assert(is(typeof(C5933d.x) == FuncType5933));
4930
4931 /***************************************************/
4932 // 6084
4933
4934 template TypeTuple6084(T...){ alias T TypeTuple6084; }
4935 void test6084()
4936 {
4937 int foo(int x)() { return x; }
4938 foreach(i; TypeTuple6084!(0))
4939 foo!(i);
4940 }
4941
4942 /***************************************************/
4943 // 6763
4944
4945 template TypeTuple6763(TList...)
4946 {
4947 alias TList TypeTuple6763;
4948 }
4949
4950 alias TypeTuple6763!(int) T6763;
4951
4952 void f6763( T6763) { } ///
4953 void c6763(const T6763) { } ///T now is (const int)
4954 void r6763(ref T6763) { } ///T now is(ref const int)
4955 void i6763(in T6763) { } ///Uncomment to get an Assertion failure in 'mtype.c'
4956 void o6763(out T6763) { } ///ditto
4957
4958 void test6763()
4959 {
4960 int n;
4961
4962 f6763(0); //With D2: Error: function main.f ((ref const const(int) _param_0)) is not callable using argument types (int)
4963 c6763(0);
4964 r6763(n); static assert(!__traits(compiles, r6763(0)));
4965 i6763(0);
4966 o6763(n); static assert(!__traits(compiles, o6763(0)));
4967
4968 // 6755
4969 static assert(typeof(f6763).stringof == "void(int _param_0)");
4970 static assert(typeof(c6763).stringof == "void(const(int) _param_0)");
4971 static assert(typeof(r6763).stringof == "void(ref int _param_0)");
4972 static assert(typeof(i6763).stringof == "void(const(int) _param_0)");
4973 static assert(typeof(o6763).stringof == "void(out int _param_0)");
4974 }
4975
4976 /***************************************************/
4977 // 6695
4978
4979 struct X6695
4980 {
4981 void mfunc()
4982 {
4983 static assert(is(typeof(this) == X6695));
4984 }
4985 void cfunc() const
4986 {
4987 static assert(is(typeof(this) == const(X6695)));
4988 }
4989 void ifunc() immutable
4990 {
4991 static assert(is(typeof(this) == immutable(X6695)));
4992 }
4993 void sfunc() shared
4994 {
4995 static assert(is(typeof(this) == shared(X6695)));
4996 }
4997 void scfunc() shared const
4998 {
4999 static assert(is(typeof(this) == shared(const(X6695))));
5000 }
5001 void wfunc() inout
5002 {
5003 static assert(is(typeof(this) == inout(X6695)));
5004 }
5005 void swfunc() shared inout
5006 {
5007 static assert(is(typeof(this) == shared(inout(X6695))));
5008 }
5009
5010 static assert(is(typeof(this) == X6695));
5011 }
5012
5013 /***************************************************/
5014 // 6087
5015
5016 template True6087(T)
5017 {
5018 immutable True6087 = true;
5019 }
5020 struct Foo6087
5021 {
5022 static assert( True6087!(typeof(this)) );
5023 }
5024
5025 struct Bar6087
5026 {
5027 static assert( is(typeof(this) == Bar6087) );
5028 }
5029
5030 /***************************************************/
5031 // 6848
5032
5033 class Foo6848 {}
5034
5035 class Bar6848 : Foo6848
5036 {
5037 void func() immutable
5038 {
5039 static assert(is(typeof(this) == immutable(Bar6848))); // immutable(Bar6848)
5040 auto t = this;
5041 static assert(is(typeof(t) == immutable(Bar6848))); // immutable(Bar6848)
5042
5043 static assert(is(typeof(super) == immutable(Foo6848))); // Foo6848 instead of immutable(Foo6848)
5044 auto s = super;
5045 static assert(is(typeof(s) == immutable(Foo6848))); // Foo6848 instead of immutable(Foo6848)
5046 }
5047 }
5048
5049 /***************************************************/
5050
5051 version(none)
5052 {
5053 cent issue785;
5054 ucent issue785;
5055 }
5056
5057 static assert(is(cent) && is(ucent) || !is(cent) && !is(ucent));
5058 static if (is(cent))
5059 static assert(__traits(compiles, { cent x; }));
5060 else
5061 static assert(!__traits(compiles, { cent x; }));
5062
5063 /***************************************************/
5064 // 6847
5065
5066 template True6847(T)
5067 {
5068 immutable True6847 = true;
5069 }
5070 class Foo6847
5071 {}
5072
5073 class Bar6847 : Foo6847
5074 {
5075 static assert( True6847!(typeof(super)) );
5076 static assert( is(typeof(super) == Foo6847) );
5077 }
5078
5079 /***************************************************/
5080 // http://d.puremagic.com/issues/show_bug.cgi?id=6488
5081
5082 struct TickDuration
5083 {
5084 template to(T) if (__traits(isIntegral,T))
5085 {
5086 const T to()
5087 {
5088 return 1;
5089 }
5090 }
5091
5092 template to(T) if (__traits(isFloating,T))
5093 {
5094 const T to()
5095 {
5096 return 0;
5097 }
5098 }
5099
5100 const long seconds()
5101 {
5102 return to!(long)();
5103 }
5104
5105 }
5106
5107 void test6488()
5108 {
5109 TickDuration d;
5110 d.seconds();
5111 }
5112
5113 /***************************************************/
5114 // 6565
5115
5116 void foo6565(out int[2][2] m) {}
5117
5118 void test6565()
5119 {
5120 int[2][2] mat = [[1, 2], [3, 4]];
5121 foo6565(mat);
5122 assert(mat == [[0, 0], [0, 0]]);
5123 }
5124
5125 /***************************************************/
5126 // 6836
5127
5128 template map6836(fun...) if (fun.length >= 1)
5129 {
5130 auto map6836(Range)(Range r)
5131 {
5132 }
5133 }
5134 void test6836()
5135 {
5136 [1].map6836!"a"();
5137 }
5138
5139 /***************************************************/
5140
5141 string func12864() { return ['a', 'b', 'c']; }
5142
5143 void test12864(string s)
5144 {
5145 switch (s)
5146 {
5147 case func12864():
5148 break;
5149
5150 default:
5151 break;
5152 }
5153 }
5154
5155 /***************************************************/
5156
5157 void test5448()
5158 {
5159 int[int][] aaa = [[1: 2]];
5160 int[string][] a2 = [["cc":0], ["DD":10]];
5161 }
5162
5163 /***************************************************/
5164 // 6837
5165
5166 struct Ref6837a(T)
5167 {
5168 T storage;
5169 alias storage this;
5170 }
5171
5172 struct Ref6837b(T)
5173 {
5174 T storage;
5175 @property ref T get(){ return storage; }
5176 alias get this;
5177 }
5178
5179 int front6837(int[] arr){ return arr[0]; }
5180
5181 void popFront6837(ref int[] arr){ arr = arr[1..$]; }
5182
5183 void test6837()
5184 {
5185 assert([1,2,3].front6837 == 1);
5186
5187 auto r1 = Ref6837a!(int[])([1,2,3]);
5188 assert(r1.front6837() == 1); // ng
5189 assert(r1.front6837 == 1); // ok
5190 r1.popFront6837(); // ng
5191 r1.storage.popFront6837(); // ok
5192
5193 auto r2 = Ref6837b!(int[])([1,2,3]);
5194 assert(r2.front6837() == 1); // ng
5195 assert(r2.front6837 == 1); // ok
5196 r2.popFront6837(); // ng
5197 r2.get.popFront6837(); // ng
5198 r2.get().popFront6837(); // ok
5199 }
5200
5201 /***************************************************/
5202 // 6927
5203
5204 @property int[] foo6927()
5205 {
5206 return [1, 2];
5207 }
5208 int[] bar6927(int[] a)
5209 {
5210 return a;
5211 }
5212 void test6927()
5213 {
5214 bar6927(foo6927); // OK
5215 foo6927.bar6927(); // line 9, Error
5216 }
5217
5218 /***************************************************/
5219
5220 struct Foo6813(T)
5221 {
5222 Foo6813 Bar()
5223 {
5224 return Foo6813(_indices.abc());
5225 }
5226
5227 T _indices;
5228 }
5229
5230 struct SortedRange(alias pred)
5231 {
5232 SortedRange abc()
5233 {
5234 return SortedRange();
5235 }
5236 }
5237
5238 void test6813() {
5239 auto ind = SortedRange!({ })();
5240 auto a = Foo6813!(typeof(ind))();
5241 }
5242
5243 /***************************************************/
5244
5245 struct Interval6753{ int a,b; }
5246 @safe struct S6753
5247 {
5248 int[] arr;
5249 @trusted @property auto byInterval() const
5250 {
5251 return cast(const(Interval6753)[])arr;
5252 }
5253 }
5254
5255 /***************************************************/
5256 // 6859
5257
5258 class Parent6859
5259 {
5260 public:
5261 bool isHage() const @property;
5262
5263 public:
5264 abstract void fuga()
5265 out
5266 {
5267 assert(isHage);
5268 }
5269 body { }
5270 }
5271
5272 class Child6859 : Parent6859
5273 {
5274 override bool isHage() const @property
5275 {
5276 return true;
5277 }
5278 override void fuga()
5279 {
5280 //nop
5281 }
5282 }
5283
5284 void test6859()
5285 {
5286 auto t = new Child6859;
5287 t.fuga();
5288 printf("done.\n");
5289 }
5290
5291 /***************************************************/
5292 // 6910
5293
5294 template Test6910(alias i, B)
5295 {
5296 void fn()
5297 {
5298 foreach(t; B.Types)
5299 {
5300 switch(i)
5301 {
5302 case 0://IndexOf!(t, B.Types):
5303 {
5304 pragma(msg, __traits(allMembers, t));
5305 pragma(msg, __traits(hasMember, t, "m"));
5306 static assert(__traits(hasMember, t, "m")); // test
5307 break;
5308 }
5309 default: {}
5310 }
5311 }
5312 }
5313 }
5314 void test6910()
5315 {
5316 static struct Bag(S...)
5317 {
5318 alias S Types;
5319 }
5320 static struct A
5321 {
5322 int m;
5323 }
5324
5325 int i;
5326 alias Test6910!(i, Bag!(A)).fn func;
5327 }
5328
5329 /***************************************************/
5330
5331 void fun12503()
5332 {
5333 string b = "abc";
5334 try
5335 {
5336 try
5337 {
5338 b = null;
5339 return;
5340 }
5341 catch
5342 {
5343 }
5344 }
5345 finally
5346 {
5347 assert("abc" !is b);
5348 }
5349 }
5350
5351 void test12503()
5352 {
5353 fun12503();
5354 }
5355
5356 /***************************************************/
5357 // 6902
5358
5359 void test6902()
5360 {
5361 static assert(is(typeof({
5362 return int.init; // int, long, real, etc.
5363 })));
5364
5365 int f() pure nothrow { assert(0); }
5366 alias int T() pure nothrow @safe @nogc;
5367 static if(is(typeof(&f) DT == delegate))
5368 {
5369 static assert(is(DT* == T*)); // ok
5370
5371 // Error: static assert (is(pure nothrow int() == pure nothrow int())) is false
5372 static assert(is(DT == T));
5373 }
5374 }
5375
5376 /***************************************************/
5377 // 6330
5378
5379 struct S6330
5380 {
5381 void opAssign(S6330 s) @disable
5382 {
5383 assert(0); // This fails.
5384 }
5385 }
5386
5387 void test6330()
5388 {
5389 S6330 s;
5390 S6330 s2;
5391 static assert(!is(typeof({ s2 = s; })));
5392 }
5393
5394 /***************************************************/
5395
5396 struct S8269
5397 {
5398 bool dtor = false;
5399 ~this()
5400 {
5401 dtor = true;
5402 }
5403 }
5404
5405 void test8269()
5406 {
5407 with(S8269())
5408 {
5409 assert(!dtor);
5410 }
5411 }
5412
5413 /***************************************************/
5414 // 5311
5415
5416 class C5311
5417 {
5418 private static int globalData;
5419
5420 void breaksPure() pure const
5421 {
5422 static assert(!__traits(compiles, { globalData++; })); // SHOULD BE ERROR
5423 static assert(!__traits(compiles, { C5311.globalData++; }));// SHOULD BE ERROR
5424 static assert(!__traits(compiles, { this.globalData++; })); // SHOULD BE ERROR
5425
5426 static assert(!__traits(compiles, { int a = this.globalData; }));
5427 }
5428 }
5429 static void breaksPure5311a(C5311 x) pure
5430 {
5431 static assert(!__traits(compiles, { x.globalData++; })); // SHOULD BE ERROR
5432
5433 static assert(!__traits(compiles, { int a = x.globalData; }));
5434 }
5435
5436 struct S5311
5437 {
5438 private static int globalData;
5439
5440 void breaksPure() pure const
5441 {
5442 static assert(!__traits(compiles, { globalData++; })); // SHOULD BE ERROR
5443 static assert(!__traits(compiles, { S5311.globalData++; }));// SHOULD BE ERROR
5444 static assert(!__traits(compiles, { this.globalData++; })); // SHOULD BE ERROR
5445
5446 static assert(!__traits(compiles, { int a = this.globalData; }));
5447 }
5448 }
5449 static void breaksPure5311b(S5311 x) pure
5450 {
5451 static assert(!__traits(compiles, { x.globalData++; })); // SHOULD BE ERROR
5452
5453 static assert(!__traits(compiles, { int a = x.globalData; }));
5454 }
5455
5456 /***************************************************/
5457 // 6868
5458
5459 @property bool empty6868(T)(in T[] a) @safe pure nothrow
5460 {
5461 return !a.length;
5462 }
5463
5464 void test6868()
5465 {
5466 alias int[] Range;
5467 static if (is(char[1 + Range.empty6868])) // Line 9
5468 enum bool isInfinite = true;
5469
5470 char[0] s; // need
5471 }
5472
5473 /***************************************************/
5474 // 2856
5475
5476 struct foo2856 { static void opIndex(int i) { printf("foo\n"); } }
5477 struct bar2856(T) { static void opIndex(int i) { printf("bar\n"); } }
5478
5479 void test2856()
5480 {
5481 foo2856[1];
5482 bar2856!(float)[1]; // Error (# = __LINE__)
5483 alias bar2856!(float) B;
5484 B[1]; // Okay
5485 }
5486
5487 /***************************************************/
5488
5489 void test13947()
5490 {
5491 struct S {}
5492 static assert(S.sizeof == 1);
5493
5494 S a;
5495 S b;
5496 *cast(ubyte*)&a = 1;
5497 *cast(ubyte*)&b = 2;
5498 assert(a == b);
5499 assert(a is b);
5500 assert(!(a != b));
5501 assert(!(a !is b));
5502 static assert(S() == S());
5503 static assert(S() is S());
5504 static assert(!(S() != S()));
5505 static assert(!(S() !is S()));
5506 }
5507
5508 /***************************************************/
5509 // 3091
5510
5511 void test3091(inout int = 0)
5512 {
5513 struct Foo {}
5514
5515 auto pm = new Foo; static assert(is( typeof( pm) == Foo * ));
5516 auto pc = new const Foo; static assert(is( typeof( pc) == const(Foo) * ));
5517 auto pw = new inout Foo; static assert(is( typeof( pw) == inout(Foo) * ));
5518 auto psm = new shared Foo; static assert(is( typeof(psm) == shared(Foo) * ));
5519 auto psc = new shared const Foo; static assert(is( typeof(psc) == shared(const(Foo))* ));
5520 auto psw = new shared inout Foo; static assert(is( typeof(psw) == shared(inout(Foo))* ));
5521 auto pi = new immutable Foo; static assert(is( typeof( pi) == immutable(Foo) * ));
5522
5523 auto m = Foo(); static assert(is( typeof( m) == Foo ));
5524 auto c = const Foo(); static assert(is( typeof( c) == const(Foo) ));
5525 auto w = inout Foo(); static assert(is( typeof( w) == inout(Foo) ));
5526 auto sm = shared Foo(); static assert(is( typeof(sm) == shared(Foo) ));
5527 auto sc = shared const Foo(); static assert(is( typeof(sc) == shared(const(Foo)) ));
5528 auto sw = shared inout Foo(); static assert(is( typeof(sw) == shared(inout(Foo)) ));
5529 auto i = immutable Foo(); static assert(is( typeof( i) == immutable(Foo) ));
5530 }
5531
5532 /***************************************************/
5533 // 6837
5534
5535 template Id6837(T)
5536 {
5537 alias T Id6837;
5538 }
5539 static assert(is(Id6837!(shared const int) == shared const int));
5540 static assert(is(Id6837!(shared inout int) == shared inout int));
5541
5542 /***************************************************/
5543 // 6056 fixup
5544
5545 template ParameterTypeTuple6056(func)
5546 {
5547 static if (is(func Fptr : Fptr*) && is(Fptr P == function))
5548 alias P ParameterTypeTuple6056;
5549 else
5550 static assert(0, "argument has no parameters");
5551 }
5552
5553 extern(C) alias void function() fpw_t;
5554
5555 alias void function(fpw_t fp) cb_t;
5556
5557 void bar6056(ParameterTypeTuple6056!(cb_t) args) {
5558 pragma (msg, "TFunction1: " ~ typeof(args[0]).stringof);
5559 }
5560
5561 extern(C) void foo6056() { }
5562
5563 void test6056()
5564 {
5565 bar6056(&foo6056);
5566 }
5567
5568 /***************************************************/
5569 // 6356
5570
5571 int f6356()(int a)
5572 {
5573 return a*a;
5574 }
5575
5576 alias f6356!() g6356; // comment this out to eliminate the errors
5577
5578 pure nothrow @safe int i6356()
5579 {
5580 return f6356(1);
5581 }
5582
5583 void test6356()
5584 {
5585 assert(i6356() == 1);
5586 }
5587
5588 /***************************************************/
5589 // 7108
5590
5591 static assert(!__traits(hasMember, int, "x"));
5592 static assert( __traits(hasMember, int, "init"));
5593
5594 /***************************************************/
5595 // 7073
5596
5597 void test7073()
5598 {
5599 string f(int[] arr...)
5600 {
5601 return "";
5602 }
5603 }
5604
5605 /***************************************************/
5606 // 7104
5607
5608 void test7104()
5609 {
5610 typeof(new class {}) c;
5611 c = new typeof(c);
5612 }
5613
5614 /***************************************************/
5615 // 7150
5616
5617 struct A7150
5618 {
5619 static int cnt;
5620
5621 this(T)(T thing, int i)
5622 {
5623 this(thing, i > 0); // Error: constructor call must be in a constructor
5624 ++cnt;
5625 }
5626 this(T)(T thing, bool b)
5627 {
5628 ++cnt;
5629 }
5630 }
5631
5632 void test7150()
5633 {
5634 auto a = A7150(5, 5); // Error: template instance constructtest.A.__ctor!(int) error instantiating
5635 assert(A7150.cnt == 2);
5636 }
5637
5638 /***************************************************/
5639 // 7159
5640
5641 alias void delegate() Void7159;
5642
5643 class HomeController7159 {
5644 Void7159 foo() {
5645 return cast(Void7159)&HomeController7159.displayDefault;
5646 }
5647 auto displayDefault() {
5648 return 1;
5649 }
5650 }
5651
5652 /***************************************************/
5653 // 7160
5654
5655 class HomeController {
5656 static if (false) {
5657 mixin(q{ int a; });
5658 }
5659 void foo() {
5660 foreach (m; __traits(derivedMembers, HomeController)) {
5661 }
5662 }
5663 }
5664
5665 void test7160()
5666 {}
5667
5668 /***************************************************/
5669 // 7168
5670
5671 void test7168()
5672 {
5673 static class X
5674 {
5675 void foo(){}
5676 }
5677 static class Y : X
5678 {
5679 void bar(){}
5680 }
5681
5682 enum ObjectMembers = ["toString","toHash","opCmp","opEquals","Monitor","factory"];
5683
5684 static assert([__traits(allMembers, X)] == ["foo"]~ObjectMembers); // pass
5685 static assert([__traits(allMembers, Y)] == ["bar", "foo"]~ObjectMembers); // fail
5686 static assert([__traits(allMembers, Y)] != ["bar", "foo"]); // fail
5687 }
5688
5689 /***************************************************/
5690 // 7170
5691
5692 T to7170(T)(string x) { return 1; }
5693 void test7170()
5694 {
5695 // auto i = to7170!int("1"); // OK
5696 auto j = "1".to7170!int(); // NG, Internal error: e2ir.c 683
5697 }
5698
5699 /***************************************************/
5700 // 7196
5701
5702 auto foo7196(int x){return x;}
5703 auto foo7196(double x){return x;}
5704
5705 void test7196()
5706 {
5707 auto x = (&foo7196)(1); // ok
5708 auto y = (&foo7196)(1.0); // fail
5709 }
5710
5711 /***************************************************/
5712 // 7285
5713
5714 int[2] spam7285()
5715 {
5716 int[2] ab;
5717 if (true)
5718 return (true) ? ab : [0, 0]; // Error
5719 else
5720 return (true) ? [0, 0] : ab; // OK
5721 }
5722
5723 void test7285()
5724 {
5725 auto sa = spam7285();
5726 }
5727
5728 /***************************************************/
5729 // 14737
5730
5731 void test14737()
5732 {
5733 // compile-time
5734 enum string[2] a1 = ["d", "e"];
5735 enum b1x = ["a", "b", "c"] ~ a1; // Tarray vs Tsarray
5736 enum b1y = a1 ~ ["a", "b", "c"]; // Tsarray vs Tarray
5737 static assert(is(typeof(b1x) == string[]));
5738 static assert(is(typeof(b1y) == string[]));
5739 static assert(b1x == ["a", "b", "c", "d", "e"]);
5740 static assert(b1y == ["d", "e", "a", "b", "c"]);
5741
5742 // runtime
5743 string[2] a2 = ["d", "e"];
5744 auto b2x = ["a", "b", "c"] ~ a2; // Tarray vs Tsarray
5745 auto b2y = a2 ~ ["a", "b", "c"]; // Tsarray vs Tarray
5746 static assert(is(typeof(b2x) == string[]));
5747 static assert(is(typeof(b2y) == string[]));
5748 assert(b2x == ["a", "b", "c", "d", "e"]);
5749 assert(b2y == ["d", "e", "a", "b", "c"]);
5750 }
5751
5752 /***************************************************/
5753 // 7321
5754
5755 void test7321()
5756 {
5757 static assert(is(typeof((){})==void function()pure nothrow @nogc @safe)); // ok
5758 static assert(is(typeof((){return;})==void function()pure nothrow @nogc @safe)); // fail
5759 }
5760
5761 /***************************************************/
5762
5763 class A158
5764 {
5765 pure void foo1() { }
5766 const void foo2() { }
5767 nothrow void foo3() { }
5768 @safe void foo4() { }
5769 }
5770
5771 class B158 : A158
5772 {
5773 override void foo1() { }
5774 override void foo2() const { }
5775 override void foo3() { }
5776 override void foo4() { }
5777 }
5778
5779 /***************************************************/
5780 // 9231
5781
5782 class B9231 { void foo() inout pure {} }
5783 class D9231 : B9231 { override void foo() inout {} }
5784
5785 /***************************************************/
5786 // 3282
5787
5788 class Base3282
5789 {
5790 string f()
5791 {
5792 return "Base.f()";
5793 }
5794 }
5795 class Derived3282 : Base3282
5796 {
5797 override string f()
5798 {
5799 return "Derived.f()";
5800 }
5801 /*override*/ string f() const
5802 {
5803 return "Derived.f() const";
5804 }
5805 }
5806
5807 void test3282()
5808 {
5809 auto x = new Base3282;
5810 assert(x.f() == "Base.f()");
5811 auto y = new Derived3282;
5812 assert(y.f() == "Derived.f()");// calls "Derived.f() const", but it is expected that be called non-const.
5813 auto z = new const(Derived3282);
5814 assert(z.f() == "Derived.f() const");
5815 }
5816
5817 /***************************************************/
5818 // 7534
5819
5820 class C7534
5821 {
5822 int foo(){ return 1; }
5823 }
5824 class D7534 : C7534
5825 {
5826 override int foo(){ return 2; }
5827 /*override*/ int foo() const { return 3; }
5828 // Error: D.foo multiple overrides of same function
5829 }
5830 void test7534()
5831 {
5832 C7534 mc = new C7534();
5833 assert(mc.foo() == 1);
5834
5835 D7534 md = new D7534();
5836 assert(md.foo() == 2);
5837 mc = md;
5838 assert(mc.foo() == 2);
5839
5840 const(D7534) cd = new const(D7534)();
5841 assert(cd.foo() == 3);
5842 md = cast()cd;
5843 assert(md.foo() == 2);
5844 }
5845
5846 /***************************************************/
5847 // 7534 + return type covariance
5848
5849 class X7534 {}
5850 class Y7534 : X7534
5851 {
5852 int value; this(int n){ value = n; }
5853 }
5854
5855 class V7534
5856 {
5857 X7534 foo(){ return new X7534(); }
5858 }
5859 class W7534 : V7534
5860 {
5861 override Y7534 foo(){ return new Y7534(1); }
5862 /*override*/ Y7534 foo() const { return new Y7534(2); }
5863 }
5864
5865 void test7534cov()
5866 {
5867 auto mv = new V7534();
5868 assert(typeid(mv.foo()) == typeid(X7534));
5869
5870 auto mw = new W7534();
5871 assert(typeid(mw.foo()) == typeid(Y7534));
5872 assert(mw.foo().value == 1);
5873 mv = mw;
5874 assert(typeid(mv.foo()) == typeid(Y7534));
5875 assert((cast(Y7534)mv.foo()).value == 1);
5876
5877 auto cw = new const(W7534)();
5878 assert(typeid(cw.foo()) == typeid(Y7534));
5879 assert(cw.foo().value == 2);
5880 }
5881
5882 /***************************************************/
5883 // 7562
5884
5885 static struct MyInt
5886 {
5887 private int value;
5888 mixin ProxyOf!value;
5889 }
5890 mixin template ProxyOf(alias a)
5891 {
5892 template X1(){}
5893 template X2(){}
5894 template X3(){}
5895 template X4(){}
5896 template X5(){}
5897 template X6(){}
5898 template X7(){}
5899 template X8(){}
5900 template X9(){}
5901 template X10(){}
5902
5903 void test1(this X)(){}
5904 void test2(this Y)(){}
5905 }
5906
5907 /***************************************************/
5908
5909 import core.stdc.stdlib;
5910
5911 void test13427(void* buffer = alloca(100))
5912 {
5913 }
5914
5915 /***************************************************/
5916 // 7583
5917
5918 template Tup7583(E...) { alias E Tup7583; }
5919
5920 struct S7583
5921 {
5922 Tup7583!(float, char) field;
5923 alias field this;
5924 this(int x) { }
5925 }
5926
5927 int bug7583() {
5928 S7583[] arr;
5929 arr ~= S7583(0);
5930 return 1;
5931 }
5932
5933 static assert (bug7583());
5934
5935 /***************************************************/
5936 // 7618
5937
5938 void test7618(const int x = 1)
5939 {
5940 int func(ref int x) { return 1; }
5941 static assert(!__traits(compiles, func(x)));
5942 // Error: function test.foo.func (ref int _param_0) is not callable using argument types (const(int))
5943
5944 int delegate(ref int) dg = (ref int x) => 1;
5945 static assert(!__traits(compiles, dg(x)));
5946 // --> no error, bad!
5947
5948 int function(ref int) fp = (ref int x) => 1;
5949 static assert(!__traits(compiles, fp(x)));
5950 // --> no error, bad!
5951 }
5952
5953 /***************************************************/
5954 // 7621
5955
5956 void test7621()
5957 {
5958 enum uint N = 4u;
5959 char[] A = "hello".dup;
5960 uint[immutable char[4u]] dict;
5961 dict[*cast(immutable char[4]*)(A[0 .. N].ptr)] = 0; // OK
5962 dict[*cast(immutable char[N]*)(A[0 .. N].ptr)] = 0; // line 6, error
5963 }
5964
5965 /***************************************************/
5966 // 7682
5967
5968 template ConstOf7682(T)
5969 {
5970 alias const(T) ConstOf7682;
5971 }
5972 bool pointsTo7682(S)(ref const S source) @trusted pure nothrow
5973 {
5974 return true;
5975 }
5976 void test7682()
5977 {
5978 shared(ConstOf7682!(int[])) x; // line A
5979
5980 struct S3 { int[10] a; }
5981 shared(S3) sh3;
5982 shared(int[]) sh3sub = sh3.a[];
5983 assert(pointsTo7682(sh3sub)); // line B
5984 }
5985
5986 /***************************************************/
5987 // 7735
5988
5989 void a7735(void[][] data...)
5990 {
5991 //writeln(data);
5992 assert(data.length == 1);
5993 b7735(data);
5994 }
5995
5996 void b7735(void[][] data...)
5997 {
5998 //writeln(data);
5999 assert(data.length == 1);
6000 c7735(data);
6001 }
6002
6003 void c7735(void[][] data...)
6004 {
6005 //writeln(data);
6006 assert(data.length == 1);
6007 }
6008
6009 void test7735()
6010 {
6011 a7735([]);
6012 a7735([]);
6013 }
6014
6015 /***************************************************/
6016
6017 struct A7823 {
6018 long a;
6019 enum A7823 b = {0};
6020 }
6021
6022 void test7823(A7823 a = A7823.b) { }
6023
6024 /***************************************************/
6025 // 7871
6026
6027 struct Tuple7871
6028 {
6029 string field;
6030 alias field this;
6031 }
6032
6033 //auto findSplitBefore(R1)(R1 haystack)
6034 auto findSplitBefore7871(string haystack)
6035 {
6036 return Tuple7871(haystack);
6037 }
6038
6039 void test7871()
6040 {
6041 string line = `<bookmark href="https://stuff">`;
6042 auto a = findSplitBefore7871(line[0 .. $])[0];
6043 }
6044
6045 /***************************************************/
6046 // 7906
6047
6048 void test7906()
6049 {
6050 static assert(!__traits(compiles, { enum s = [string.min]; }));
6051 }
6052
6053 /***************************************************/
6054 // 7907
6055
6056 template Id7907(E)
6057 {
6058 alias E Id7907;
6059 }
6060 template Id7907(alias E)
6061 {
6062 alias E Id7907;
6063 }
6064
6065 void test7907()
6066 {
6067 static assert(!__traits(compiles, { alias Id7907!([string.min]) X; }));
6068 }
6069
6070 /***************************************************/
6071 // 1175
6072
6073 class A1175
6074 {
6075 class I1 { }
6076 }
6077
6078 class B1175 : A1175
6079 {
6080 class I2 : I1 { }
6081
6082 I1 getI() { return new I2; }
6083 }
6084
6085 /***************************************************/
6086 // 7983
6087
6088 class A7983 {
6089 void f() {
6090 g7983(this);
6091 }
6092 unittest {
6093 }
6094 }
6095
6096 void g7983(T)(T a)
6097 {
6098 foreach (name; __traits(allMembers, T)) {
6099 pragma(msg, name);
6100 static if (__traits(compiles, &__traits(getMember, a, name)))
6101 {
6102 }
6103 }
6104 }
6105
6106 /***************************************************/
6107 // 8004
6108
6109 void test8004()
6110 {
6111 auto n = (int n = 10){ return n; }();
6112 assert(n == 10);
6113 }
6114
6115 /***************************************************/
6116 // 8064
6117
6118 void test8064()
6119 {
6120 uint[5] arry;
6121 ref uint acc(size_t i) {
6122 return arry[i];
6123 }
6124 auto arryacc = &acc;
6125 arryacc(3) = 5; // same error
6126 }
6127
6128 /***************************************************/
6129 // 8220
6130
6131 void foo8220(int){}
6132 static assert(!__traits(compiles, foo8220(typeof(0)))); // fail
6133
6134 /***************************************************/
6135
6136 void func8105(in ref int x) { }
6137
6138 void test8105()
6139 {
6140 }
6141
6142 /***************************************************/
6143
6144 template ParameterTypeTuple159(alias foo)
6145 {
6146 static if (is(typeof(foo) P == __parameters))
6147 alias P ParameterTypeTuple159;
6148 else
6149 static assert(0, "argument has no parameters");
6150 }
6151
6152 int func159(int i, long j = 7) { return 3; }
6153
6154 alias ParameterTypeTuple159!func159 PT;
6155
6156 int bar159(PT) { return 4; }
6157
6158 pragma(msg, typeof(bar159));
6159 pragma(msg, PT[1]);
6160
6161 PT[1] boo159(PT[1..2] a) { return a[0]; }
6162
6163 void test159()
6164 {
6165 assert(bar159(1) == 4);
6166 assert(boo159() == 7);
6167 }
6168
6169 /***************************************************/
6170 // 8283
6171
6172 struct Foo8283 {
6173 this(long) { }
6174 }
6175
6176 struct FooContainer {
6177 Foo8283 value;
6178 }
6179
6180 auto get8283() {
6181 union Buf { FooContainer result; }
6182 Buf buf = {};
6183 return buf.result;
6184 }
6185
6186 void test8283() {
6187 auto a = get8283();
6188 }
6189
6190
6191 /***************************************************/
6192 // 8395
6193
6194 struct S8395
6195 {
6196 int v;
6197 this(T : long)(T x) { v = x * 2; }
6198 }
6199 void test8395()
6200 {
6201 S8395 ms = 6;
6202 assert(ms.v == 12);
6203 const S8395 cs = 7;
6204 assert(cs.v == 14);
6205 }
6206
6207 /***************************************************/
6208 // 5749
6209
6210 void test5749()
6211 {
6212 static struct A
6213 {
6214 A foo(int x, int i)
6215 {
6216 //printf("this = %p, %d: i=%d\n", &this, x, i);
6217 assert(i == x);
6218 return this;
6219 }
6220 A bar(int x, ref int i)
6221 {
6222 //printf("this = %p, %d: i=%d\n", &this, x, i);
6223 assert(i == x);
6224 return this;
6225 }
6226 }
6227
6228 static int inc1(ref int i) { return ++i; }
6229 static ref int inc2(ref int i) { return ++i; }
6230
6231 int i;
6232 A a;
6233 //printf("&a = %p\n", &a);
6234
6235 i = 0; a.foo(1, ++i).foo(2, ++i); // OK <-- 2 1
6236 i = 0; a.bar(1, ++i).bar(2, ++i); // OK <-- 2 2
6237 i = 0; a.foo(1, inc1(i)).foo(2, inc1(i)); // OK <-- 2 1
6238 i = 0; a.bar(1, inc2(i)).bar(2, inc2(i)); // OK <-- 2 2
6239 //printf("\n");
6240
6241 A getVal() { static A a; return a; }
6242 i = 0; getVal().foo(1, ++i).foo(2, ++i); // OK <-- 2 1
6243 i = 0; getVal().bar(1, ++i).bar(2, ++i); // OK <-- 2 2
6244 i = 0; getVal().foo(1, inc1(i)).foo(2, inc1(i)); // OK <-- 2 1
6245 i = 0; getVal().bar(1, inc2(i)).bar(2, inc2(i)); // OK <-- 2 2
6246 //printf("\n");
6247
6248 ref A getRef() { static A a; return a; }
6249 i = 0; getRef().foo(1, ++i).foo(2, ++i); // OK <-- 2 1
6250 i = 0; getRef().bar(1, ++i).bar(2, ++i); // OK <-- 2 2
6251 i = 0; getRef().foo(1, inc1(i)).foo(2, inc1(i)); // OK <-- 2 1
6252 i = 0; getRef().bar(1, inc2(i)).bar(2, inc2(i)); // OK <-- 2 2
6253 }
6254
6255 /***************************************************/
6256 // 8396
6257
6258 void test8396()
6259 {
6260 static int g;
6261
6262 static extern(C) int bar(int a, int b)
6263 {
6264 //printf("a = %d, b = %d\n", a, b);
6265 assert(b - a == 1);
6266 return ++g;
6267 }
6268 static auto getFunc(int n)
6269 {
6270 assert(++g == n);
6271 return &bar;
6272 }
6273
6274 static struct Tuple { int _a, _b; }
6275 static Tuple foo(int n)
6276 {
6277 assert(++g == n);
6278 return Tuple(1, 2);
6279 }
6280
6281 g = 0;
6282 assert(bar(foo(1).tupleof) == 2);
6283
6284 g = 0;
6285 assert(getFunc(1)(foo(2).tupleof) == 3);
6286 }
6287
6288 /***************************************************/
6289
6290 enum E160 : ubyte { jan = 1 }
6291
6292 struct D160
6293 {
6294 short _year = 1;
6295 E160 _month = E160.jan;
6296 ubyte _day = 1;
6297
6298 this(int year, int month, int day) pure
6299 {
6300 _year = cast(short)year;
6301 _month = cast(E160)month;
6302 _day = cast(ubyte)day;
6303 }
6304 }
6305
6306 struct T160
6307 {
6308 ubyte _hour;
6309 ubyte _minute;
6310 ubyte _second;
6311
6312 this(int hour, int minute, int second = 0) pure
6313 {
6314 _hour = cast(ubyte)hour;
6315 _minute = cast(ubyte)minute;
6316 _second = cast(ubyte)second;
6317 }
6318 }
6319
6320 struct DT160
6321 {
6322 D160 _date;
6323 T160 _tod;
6324
6325 this(int year, int month, int day,
6326 int hour = 0, int minute = 0, int second = 0) pure
6327 {
6328 _date = D160(year, month, day);
6329 _tod = T160(hour, minute, second);
6330 }
6331 }
6332
6333 void foo160(DT160 dateTime)
6334 {
6335 printf("test7 year %d, day %d\n", dateTime._date._year, dateTime._date._day);
6336 assert(dateTime._date._year == 1999);
6337 assert(dateTime._date._day == 6);
6338 }
6339
6340 void test160()
6341 {
6342 auto dateTime = DT160(1999, 7, 6, 12, 30, 33);
6343 printf("test5 year %d, day %d\n", dateTime._date._year, dateTime._date._day);
6344 assert(dateTime._date._year == 1999);
6345 assert(dateTime._date._day == 6);
6346 foo160(DT160(1999, 7, 6, 12, 30, 33));
6347 }
6348
6349 /***************************************************/
6350 // 8437
6351
6352 class Cgi8437
6353 {
6354 struct PostParserState {
6355 UploadedFile piece;
6356 }
6357
6358 static struct UploadedFile {
6359 string contentFilename;
6360 }
6361 }
6362
6363 /***************************************************/
6364 // 8665
6365
6366 auto foo8665a(bool val)
6367 {
6368 if (val)
6369 return 42;
6370 else
6371 return 1.5;
6372 }
6373 auto foo8665b(bool val)
6374 {
6375 if (!val)
6376 return 1.5;
6377 else
6378 return 42;
6379 }
6380
6381 void test8665()
6382 {
6383 static assert(is(typeof(foo8665a(true)) == double));
6384 static assert(is(typeof(foo8665b(false)) == double));
6385 assert(foo8665a(true) == 42); // assertion failure
6386 assert(foo8665b(true) == 42); // assertion failure
6387 assert(foo8665a(false) == 1.5);
6388 assert(foo8665b(false) == 1.5);
6389
6390 static assert(foo8665a(true) == 42);
6391 static assert(foo8665b(true) == 42);
6392 static assert(foo8665a(false) == 1.5);
6393 static assert(foo8665b(false) == 1.5);
6394 }
6395
6396 /***************************************************/
6397
6398 int foo8108(int, int);
6399
6400 int foo8108(int a, int b)
6401 {
6402 return a + b;
6403 }
6404
6405 void test8108()
6406 {
6407 foo8108(1,2);
6408 }
6409
6410 /***************************************************/
6411 // 8360
6412
6413 struct Foo8360
6414 {
6415 int value = 0;
6416 int check = 1337;
6417
6418 this(int value)
6419 {
6420 assert(0);
6421 this.value = value;
6422 }
6423
6424 ~this()
6425 {
6426 assert(0);
6427 assert(check == 1337);
6428 }
6429
6430 string str()
6431 {
6432 assert(0);
6433 return "Foo";
6434 }
6435 }
6436
6437 Foo8360 makeFoo8360()
6438 {
6439 assert(0);
6440 return Foo8360(2);
6441 }
6442
6443 void test8360()
6444 {
6445 size_t length = 0;
6446
6447 // The message part 'makeFoo().str()' should not be evaluated at all.
6448 assert(length < 5, makeFoo8360().str());
6449 }
6450
6451 /***************************************************/
6452 // 8361
6453
6454 struct Foo8361
6455 {
6456 string bar = "hello";
6457 ~this() {}
6458 }
6459
6460 void test8361()
6461 {
6462 assert(true, Foo8361().bar);
6463 }
6464
6465 /***************************************************/
6466 // 6141 + 8526
6467
6468 void test6141()
6469 {
6470 static void takeADelegate(void delegate()) {}
6471 auto items = new int[1];
6472 items[0] = 17;
6473 foreach (ref item; items)
6474 {
6475 // both asserts fail
6476 assert(item == 17);
6477 assert(&item == items.ptr);
6478
6479 takeADelegate({ auto x = &item; });
6480 }
6481
6482 foreach(ref val; [3])
6483 {
6484 auto dg = { int j = val; };
6485 assert(&val != null); // Assertion failure
6486 assert(val == 3);
6487 }
6488
6489 static void f(lazy int) {}
6490 int i = 0;
6491 auto dg = { int j = i; };
6492 foreach(ref val; [3])
6493 {
6494 f(val);
6495 assert(&val != null); // Assertion failure
6496 assert(val == 3);
6497 }
6498 }
6499
6500 void test8526()
6501 {
6502 static void call(void delegate() dg) { dg(); }
6503
6504 foreach (i, j; [0])
6505 {
6506 call({
6507 assert(i == 0); // fails, i is corrupted
6508 });
6509 }
6510
6511 foreach (n; 0..1)
6512 {
6513 call({
6514 assert(n == 0); // fails, n is corrupted
6515 });
6516 }
6517 }
6518
6519 /***************************************************/
6520
6521 template ParameterTuple(alias func)
6522 {
6523 static if(is(typeof(func) P == __parameters))
6524 alias P ParameterTuple;
6525 else
6526 static assert(0);
6527 }
6528
6529 int foo161(ref float y);
6530
6531 void test161()
6532 {
6533 alias PT = ParameterTuple!foo161;
6534 auto x = __traits(identifier, PT);
6535 assert(x == "y");
6536 }
6537
6538 /***************************************************/
6539 // 7175
6540
6541 void test7175()
6542 {
6543 struct S { ubyte[0] arr; }
6544 S s;
6545 assert(s.arr.ptr !is null);
6546 assert(cast(void*)s.arr.ptr is cast(void*)&s);
6547 }
6548
6549 /***************************************************/
6550 // 8819
6551
6552 void test8819()
6553 {
6554 void[1] sa1 = (void[1]).init;
6555 assert((cast(ubyte*)sa1.ptr)[0] == 0);
6556
6557 void[4] sa4 = [cast(ubyte)1,cast(ubyte)2,cast(ubyte)3,cast(ubyte)4];
6558 assert((cast(ubyte*)sa4.ptr)[0] == 1);
6559 assert((cast(ubyte*)sa4.ptr)[1] == 2);
6560 assert((cast(ubyte*)sa4.ptr)[2] == 3);
6561 assert((cast(ubyte*)sa4.ptr)[3] == 4);
6562
6563 auto sa22 = (void[2][2]).init;
6564 static assert(sa22.sizeof == ubyte.sizeof * 2 * 2);
6565 ubyte[4]* psa22 = cast(ubyte[4]*)sa22.ptr;
6566 assert((*psa22)[0] == 0);
6567 assert((*psa22)[1] == 0);
6568 assert((*psa22)[2] == 0);
6569 assert((*psa22)[3] == 0);
6570 }
6571
6572 /***************************************************/
6573 // 8897
6574
6575 class C8897
6576 {
6577 static mixin M8897!(int);
6578 static class causesAnError {}
6579 }
6580
6581 template M8897 ( E ) { }
6582
6583 /***************************************************/
6584 // 8917
6585
6586 void test8917()
6587 {
6588 int[3] a;
6589 int[3] a2;
6590 int[3] b = a[] + a2[];
6591 }
6592
6593 /***************************************************/
6594 // 8945
6595
6596 struct S8945 // or `class`, or `union`
6597 {
6598 struct S0(T) { int i; }
6599 struct S1(T) { this(int){} }
6600 }
6601
6602 void test8945()
6603 {
6604 auto cs0a = const S8945.S0!int(); // ok
6605 auto cs0b = const S8945.S0!int(1); // ok
6606 auto cs1 = const S8945.S1!int(1); // ok
6607
6608 auto s0a = S8945.S0!int(); // Error: struct S0 does not overload ()
6609 auto s0b = S8945.S0!int(1); // Error: struct S0 does not overload ()
6610 auto s1 = S8945.S1!int(1); // Error: struct S1 does not overload ()
6611 }
6612
6613 /***************************************************/
6614
6615 struct S162
6616 {
6617 static int generateMethodStubs( Class )()
6618 {
6619 int text;
6620
6621 foreach( m; __traits( allMembers, Class ) )
6622 {
6623 static if( is( typeof( mixin( m ) ) ) && is( typeof( mixin( m ) ) == function ) )
6624 {
6625 pragma(msg, __traits( getOverloads, Class, m ));
6626 }
6627 }
6628
6629 return text;
6630 }
6631
6632 enum int ttt = generateMethodStubs!( S162 )();
6633
6634 float height();
6635 int get( int );
6636 int get( long );
6637 void clear();
6638
6639 void draw( int );
6640 void draw( long );
6641 }
6642
6643 /***************************************************/
6644
6645 void test163() {
6646 static class C { int x; int y; }
6647
6648 immutable C c = new C();
6649 shared C c2 = new C();
6650 shared const C c3 = new C();
6651
6652 class D { int x; int y; }
6653 immutable D d;
6654 assert(!__traits(compiles, d = new D()));
6655
6656 static struct S { int x; int y; }
6657
6658 immutable S* s = new S();
6659 shared S* s2 = new S();
6660 shared const S* s3 = new S();
6661
6662 shared S* s4;
6663 assert(__traits(compiles, s4 = new immutable(S)()));
6664
6665 struct T { int x; int y; }
6666 immutable T* t;
6667 assert(!__traits(compiles, t = new T()));
6668
6669 immutable int* pi = new int();
6670 immutable void* pv = new int();
6671
6672 immutable int[] ai = new int[1];
6673 immutable void[] av = new int[2];
6674 }
6675
6676 /***************************************************/
6677 struct S9000
6678 { ubyte i = ubyte.max; }
6679
6680 enum E9000 = S9000.init;
6681
6682 /***************************************************/
6683
6684 mixin template DefineCoreType(string type)
6685 {
6686 struct Faulty
6687 {
6688 static int x;
6689
6690 static void instance()
6691 {
6692 x = 3;
6693 }
6694
6695 X164!() xxx;
6696 }
6697 }
6698
6699 mixin DefineCoreType!("");
6700
6701
6702 mixin template A164()
6703 {
6704 static this()
6705 {
6706 }
6707 }
6708
6709 struct X164()
6710 {
6711 mixin A164!();
6712 }
6713
6714
6715 /***************************************************/
6716 // 9428
6717
6718 void test9428()
6719 {
6720 int[2][] items = [[1, 2]];
6721 int[2] x = [3, 4];
6722
6723 auto r1 = items ~ [x];
6724 assert(r1.length == 2);
6725 assert(r1[0][0] == 1);
6726 assert(r1[0][1] == 2);
6727 assert(r1[1][0] == 3);
6728 assert(r1[1][1] == 4);
6729
6730 auto r2 = items ~ x;
6731 assert(r2.length == 2);
6732 assert(r2[0][0] == 1);
6733 assert(r2[0][1] == 2);
6734 assert(r2[1][0] == 3);
6735 assert(r2[1][1] == 4);
6736
6737 auto r3 = [x] ~ items;
6738 assert(r3.length == 2);
6739 assert(r3[0][0] == 3);
6740 assert(r3[0][1] == 4);
6741 assert(r3[1][0] == 1);
6742 assert(r3[1][1] == 2);
6743
6744 auto r4 = x ~ items;
6745 assert(r4.length == 2);
6746 assert(r4[0][0] == 3);
6747 assert(r4[0][1] == 4);
6748 assert(r4[1][0] == 1);
6749 assert(r4[1][1] == 2);
6750 }
6751
6752 /***************************************************/
6753 // 9477
6754
6755 template Tuple9477(T...) { alias T Tuple9477; }
6756 template Select9477(bool b, T, U) { static if (b) alias T Select9477; else alias U Select9477; }
6757
6758 void test9477()
6759 {
6760 static bool isEq (T1, T2)(T1 s1, T2 s2) { return s1 == s2; }
6761 static bool isNeq(T1, T2)(T1 s1, T2 s2) { return s1 != s2; }
6762
6763 // Must be outside the loop due to http://d.puremagic.com/issues/show_bug.cgi?id=9748
6764 int order;
6765 // Must be outside the loop due to http://d.puremagic.com/issues/show_bug.cgi?id=9756
6766 auto checkOrder(bool dyn, uint expected)()
6767 {
6768 assert(order==expected);
6769 order++;
6770 // Use temporary ("v") to work around http://d.puremagic.com/issues/show_bug.cgi?id=9402
6771 auto v = cast(Select9477!(dyn, string, char[1]))"a";
6772 return v;
6773 }
6774
6775 foreach (b1; Tuple9477!(false, true))
6776 foreach (b2; Tuple9477!(false, true))
6777 {
6778 version (D_PIC) {} else // Work around http://d.puremagic.com/issues/show_bug.cgi?id=9754
6779 {
6780 assert( isEq (cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[0]))"" ));
6781 assert(!isNeq(cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[0]))"" ));
6782
6783 assert(!isEq (cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[1]))"a" ));
6784 assert( isNeq(cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[1]))"a" ));
6785 }
6786
6787 assert( isEq (cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"a" ));
6788 assert(!isNeq(cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"a" ));
6789
6790 assert(!isEq (cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"b" ));
6791 assert( isNeq(cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"b" ));
6792
6793 assert(!isEq (cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[2]))"aa"));
6794 assert( isNeq(cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[2]))"aa"));
6795
6796 // Note: order of evaluation was not followed before this patch
6797 // (thus, the test below will fail without the patch).
6798 // Although the specification mentions that as implementation-defined behavior,
6799 // I understand that this isn't by design, but rather an inconvenient aspect of DMD
6800 // that has been moved to the specification.
6801 order = 0;
6802 bool result = checkOrder!(b1, 0)() == checkOrder!(b2, 1)();
6803 assert(result);
6804 assert(order == 2);
6805 }
6806
6807 // need largest natural alignment to avoid unaligned access on
6808 // some architectures, double in this case.
6809 align(8) ubyte[64] a1, a2;
6810 foreach (T; Tuple9477!(void, ubyte, ushort, uint, ulong, char, wchar, dchar, float, double))
6811 {
6812 auto s1 = cast(T[])(a1[]);
6813 auto s2 = cast(T[])(a2[]);
6814 assert(s1 == s2);
6815 a2[$-1]++;
6816 assert(s1 != s2);
6817 assert(s1[0..$-1]==s2[0..$-1]);
6818 a2[$-1]--;
6819 }
6820 }
6821
6822 /***************************************************/
6823 // 9504
6824
6825 struct Bar9504
6826 {
6827 template Abc(T)
6828 {
6829 T y;
6830 }
6831
6832 enum size_t num = 123;
6833
6834 class Def {}
6835 }
6836
6837 template GetSym9504(alias sym) { static assert(__traits(isSame, sym, Bar9504.Abc)); }
6838 template GetExp9504(size_t n) { static assert(n == Bar9504.num); }
6839 template GetTyp9504(T) { static assert(is(T == Bar9504.Def)); }
6840
6841 alias GetSym9504!(typeof(Bar9504.init).Abc) X9504; // NG
6842 alias GetExp9504!(typeof(Bar9504.init).num) Y9504; // NG
6843 alias GetTyp9504!(typeof(Bar9504.init).Def) Z9504;
6844
6845 Bar9504 test9504()
6846 {
6847 alias GetSym9504!(typeof(return).Abc) V9504; // NG
6848 alias GetExp9504!(typeof(return).num) W9504; // NG
6849 alias GetTyp9504!(typeof(return).Def) X9504;
6850 return Bar9504();
6851 }
6852
6853 /***************************************************/
6854 // 9538
6855
6856 void test9538()
6857 {
6858 void*[1] x;
6859 auto ti = typeid(x.ptr);
6860 }
6861
6862 /***************************************************/
6863 // 9539
6864
6865 void test9539()
6866 {
6867 void f(int** ptr)
6868 {
6869 assert(**ptr == 10);
6870 }
6871 int* p = new int;
6872 *p = 10;
6873 int*[1] x = [p];
6874 f(&x[0]);
6875
6876 int*[] arr = [null];
6877 static assert(!__traits(compiles, p = arr)); // bad!
6878 }
6879
6880 /***************************************************/
6881 // 9700
6882
6883 mixin template Proxy9700(alias a)
6884 {
6885 auto ref opOpAssign(string op, V)(V v) { return a += v; } // NG
6886 //auto ref opOpAssign(string op, V)(V v) { a += v; } // OK
6887 }
6888 struct MyInt9700
6889 {
6890 int value;
6891 invariant() { assert(value >= 0); }
6892 mixin Proxy9700!value;
6893 }
6894 void test9700()
6895 {
6896 MyInt9700 a = { 2 };
6897 a *= 3; // object.Error: Access Violation
6898 }
6899
6900 /***************************************************/
6901 // 9834
6902
6903 struct Event9834
6904 {
6905 void delegate() dg;
6906 void set(void delegate() h) pure { dg = h; } // AV occurs
6907 void call() { dg(); }
6908 }
6909 void test9834()
6910 {
6911 Event9834 ev;
6912 auto a = new class
6913 {
6914 Object o;
6915 this()
6916 {
6917 o = new Object;
6918 ev.set((){ o.toString(); });
6919 }
6920 };
6921 ev.call();
6922 }
6923
6924 /***************************************************/
6925 // 9859
6926
6927 void test9859(inout int[] arr)
6928 {
6929 auto dg1 = { foreach (i, e; arr) { } };
6930 dg1();
6931
6932 void foo() { auto v = arr; auto w = arr[0]; }
6933 void bar(inout int i) { auto v = arr[i]; }
6934
6935 auto dg2 =
6936 {
6937 auto dg =
6938 {
6939 void foo(T)()
6940 {
6941 auto dg =
6942 {
6943 auto dg =
6944 {
6945 auto v = arr;
6946 };
6947 };
6948 }
6949 foo!int;
6950 };
6951 };
6952
6953 void qux(T)()
6954 {
6955 auto v = arr;
6956 auto dg1 = { auto v = arr; };
6957 auto dg2 =
6958 {
6959 auto dg =
6960 {
6961 auto v = arr;
6962 };
6963 };
6964 }
6965 qux!int;
6966 }
6967
6968 /***************************************************/
6969 // 9912
6970
6971 template TypeTuple9912(Stuff...)
6972 {
6973 alias Stuff TypeTuple9912;
6974 }
6975
6976 struct S9912
6977 {
6978 int i;
6979 alias TypeTuple9912!i t;
6980
6981 void testA() {
6982 auto x = t;
6983 }
6984
6985 void testB() {
6986 auto x = t;
6987 }
6988 }
6989
6990 /***************************************************/
6991 // 9883
6992
6993 struct S9883
6994 {
6995 @property size_t p9883(T)() { return 0; }
6996 }
6997
6998 @property size_t p9883(T)() { return 0; }
6999
7000 void test9883()
7001 {
7002 S9883 s;
7003 auto n1 = p9883!int; // OK
7004 auto n2 = s.p9883!int; // OK
7005 auto a1 = new int[p9883!int]; // Error: need size of rightmost array, not type p!(int)
7006 auto a2 = new int[s.p9883!int]; // Error: no property 'p!(int)' for type 'S'
7007 }
7008
7009
7010 /***************************************************/
7011 // 10091
7012
7013 struct S10091
7014 {
7015 enum e = "a";
7016 }
7017
7018 void test10091()
7019 {
7020 auto arr = cast(ubyte[1]) S10091.e;
7021 }
7022
7023 /***************************************************/
7024
7025 void test12824()
7026 {
7027 label:
7028 static if (0)
7029 {
7030 }
7031 }
7032
7033 /***************************************************/
7034 // 9130
7035
7036 class S9130 { void bar() { } }
7037
7038 import core.stdc.stdio : printf;
7039
7040 struct Function
7041 {
7042 int[] ai = [1,2,3];
7043 }
7044
7045 @property void meta(alias m)()
7046 {
7047 static Function md;
7048 printf("length = %d\n", md.ai.length);
7049 printf("ptr = %p\n", md.ai.ptr);
7050 md.ai[0] = 0;
7051 }
7052
7053 void test9130()
7054 {
7055 meta!(__traits(getOverloads, S9130, "bar")[0]);
7056 meta!(S9130.bar);
7057 }
7058
7059 /***************************************************/
7060 // 10390
7061
7062 class C10390 { this() { this.c = this; } C10390 c; }
7063 const c10390 = new C10390();
7064 pragma(msg, c10390);
7065
7066 /***************************************************/
7067 // 10542
7068
7069 class B10542
7070 {
7071 this() nothrow pure @safe { }
7072 }
7073
7074 class D10542 : B10542
7075 {
7076 }
7077
7078 void test10542() nothrow pure @safe
7079 {
7080 new D10542;
7081 }
7082
7083 /***************************************************/
7084 // 10539
7085
7086 void test10539()
7087 {
7088 int[2][2] a;
7089 int* p1 = a.ptr.ptr; // OK <- error
7090 int* p2 = (*a.ptr).ptr; // OK
7091 assert(p1 is p2);
7092 }
7093
7094 /***************************************************/
7095
7096 struct TimeOfDay
7097 {
7098 ubyte h, m, s;
7099 }
7100
7101 __gshared byte glob;
7102
7103 struct DateTime
7104 {
7105 this(ubyte _d, ubyte _m, ubyte _y, TimeOfDay _tod = TimeOfDay.init)
7106 {
7107 d = _d;
7108 m = _m;
7109 y = _y;
7110 tod = _tod;
7111 }
7112 TimeOfDay tod;
7113 ubyte d, m, y;
7114 }
7115
7116
7117 void test10634()
7118 {
7119 glob = 123;
7120 DateTime date1 = DateTime(0, 0, 0);
7121 DateTime date2;
7122 assert(date1 == date2);
7123 }
7124
7125 /***************************************************/
7126
7127 immutable(char)[4] bar7254(int i)
7128 {
7129 if (i)
7130 {
7131 immutable(char)[4] r; return r;
7132 }
7133 else
7134 return "1234";
7135 }
7136
7137 void test7254()
7138 {
7139 assert(bar7254(0) == "1234");
7140 }
7141
7142 /***************************************************/
7143
7144 struct S11075() { int x = undefined_expr; }
7145
7146 class C11075() { int x = undefined_expr; }
7147
7148 interface I11075() { enum int x = undefined_expr; }
7149
7150 void test11075()
7151 {
7152 static assert(!is(typeof(S11075!().x)));
7153 static assert(!is(typeof(S11075!().x)));
7154
7155 static assert(!is(typeof(C11075!().x)));
7156 static assert(!is(typeof(C11075!().x)));
7157
7158 static assert(!is(typeof(I11075!().x)));
7159 static assert(!is(typeof(I11075!().x)));
7160 }
7161
7162 /***************************************************/
7163 // 11181
7164
7165 void test11181()
7166 {
7167 auto a = ["a", "b"];
7168
7169 static assert(!is(typeof([a, "x"])));
7170 static assert(!is(typeof(true ? a : "x")));
7171
7172 static assert(!is(typeof(true ? a[0 .. $] : "x")));
7173 static assert(!is(typeof([a[0 .. $], "x"])));
7174 }
7175
7176 /***************************************************/
7177 // 11317
7178
7179 void test11317()
7180 {
7181 auto ref uint fun()
7182 {
7183 return 0;
7184 }
7185
7186 void test(ref uint x) {}
7187 static assert(!__traits(compiles, test(fun())));
7188
7189 assert(fun() == 0);
7190 }
7191
7192 /***************************************************/
7193 // 11888
7194
7195 void test11888()
7196 {
7197 static long val;
7198
7199 static ubyte* foo(size_t* len)
7200 {
7201 *len = val.sizeof;
7202 return cast(ubyte*)&val;
7203 }
7204
7205 size_t size;
7206 ubyte[] t = foo(&size)[0..size];
7207 assert(t.ptr is cast(void*)&val);
7208 assert(t.length == 8);
7209
7210 // regression test
7211 int[3] sa1 = [1,2,3];
7212 int[1] sa2 = sa1[1..2]; // convert slice to Tsarray
7213 assert(sa2.length == 1);
7214 assert(sa2[0] == 2);
7215 }
7216
7217 /***************************************************/
7218 // 12036
7219
7220 template T12036(alias a)
7221 {
7222 string value;
7223 }
7224
7225 struct S12036
7226 {
7227 auto fun() { }
7228 mixin T12036!fun;
7229 }
7230
7231 void test12036()
7232 {
7233 S12036 s;
7234 assert(s.value == "");
7235 }
7236
7237 /***************************************************/
7238 // 12153
7239
7240 void test12153()
7241 {
7242 int[1] i, j;
7243 bool b = true;
7244 (b ? i : j)[] = [4];
7245 assert(i == [4]);
7246
7247 // regression test
7248 int[1][1] k, l;
7249 (b ? k : l)[0..1][0..1] = [4];
7250 assert(k == [[4]]);
7251 }
7252
7253 /***************************************************/
7254 // 12498
7255
7256 string a12498()
7257 {
7258 string b;
7259 while (b) { }
7260 for (; b; ) { }
7261 return "";
7262 }
7263
7264 void test12498()
7265 {
7266 enum t = a12498();
7267 string x = t;
7268 }
7269
7270 /***************************************************/
7271 // 12900
7272
7273 struct A12900
7274 {
7275 char[1] b;
7276 }
7277
7278 void test12900()
7279 {
7280 A12900 c;
7281 if (*c.b.ptr)
7282 return;
7283 }
7284
7285 /***************************************************/
7286 // 12937
7287
7288 void test12937()
7289 {
7290 void[1] sa2 = cast(void[])[cast(ubyte)1]; // ICE!
7291 assert((cast(ubyte[])sa2[])[0] == 1);
7292 }
7293
7294 /***************************************************/
7295 // 13154
7296
7297 void test13154()
7298 {
7299 int[3] ints = [2 , 1 , 0 , 1 ][0..3];
7300 float[3] floats0 = [2f , 1f , 0f , 1f ][0..3];
7301 float[3] floats1 = [2.0 , 1.0 , 0.0 , 1.0 ][0..3]; // fails!
7302 float[3] floats2 = [2.0f, 1.0f, 0.0f, 1.0f][0..3];
7303 assert(ints == [2, 1, 0]);
7304 assert(floats0 == [2, 1, 0]);
7305 assert(floats1 == [2, 1, 0]); // fail!
7306 assert(floats1 != [0, 0, 0]); // fail!
7307 assert(floats2 == [2, 1, 0]);
7308 }
7309
7310 /***************************************************/
7311 // 13437
7312
7313 ubyte[4] foo13437() { return [1,2,3,4]; }
7314
7315 void test13437()
7316 {
7317 auto n = cast(ubyte[4])foo13437()[]; // OK <- ICE: e2ir.c 4616
7318 static assert(is(typeof(n) == ubyte[4]));
7319 assert(n == [1,2,3,4]);
7320 }
7321
7322 /***************************************************/
7323 // 13472
7324
7325 class A13472
7326 {
7327 int a;
7328 }
7329
7330 void test13472()
7331 {
7332 A13472[] test;
7333 test.length = 4;
7334 auto b = test[0..2] ~ null ~ test[2..$];
7335 assert(b.length == 5);
7336 }
7337
7338 /***************************************************/
7339 // 13476
7340
7341 template ParameterTypeTuple13476(func...)
7342 {
7343 static if (is(typeof(*func[0]) P == function))
7344 alias ParameterTypeTuple13476 = P;
7345 else
7346 static assert(0, "argument has no parameters");
7347 }
7348
7349 int flag13476;
7350
7351 __gshared extern(C) void function(int) nothrow someFunc13476 = &Stub13476!someFunc13476;
7352
7353 extern(C) auto Stub13476(alias func)(ParameterTypeTuple13476!func args)
7354 {
7355 ++flag13476;
7356 extern(C) void function(int) nothrow impl = (i) { };
7357 return (func = impl)(args);
7358 }
7359
7360 __gshared extern(C) void function(int) nothrow someFunc13476Alt = &Stub13476Alt!someFunc13476AltP;
7361 __gshared extern(C) void function(int) nothrow* someFunc13476AltP = &someFunc13476Alt;
7362
7363 extern(C) auto Stub13476Alt(alias func)(int args) nothrow
7364 {
7365 ++flag13476;
7366 extern(C) void function(int) nothrow impl = (i) {};
7367 return (*func = impl)(args);
7368 }
7369
7370 void test13476()
7371 {
7372 assert(flag13476 == 0);
7373
7374 someFunc13476(42);
7375 assert(flag13476 == 1);
7376 someFunc13476(43);
7377 assert(flag13476 == 1);
7378
7379 someFunc13476Alt(42);
7380 assert(flag13476 == 2);
7381 someFunc13476Alt(43);
7382 assert(flag13476 == 2);
7383 }
7384
7385 /***************************************************/
7386 // 14038
7387
7388 static immutable ubyte[string] wordsAA14038;
7389 static this()
7390 {
7391 wordsAA14038["zero"] = 0;
7392 }
7393
7394 /***************************************************/
7395 // 14192
7396
7397 void test14192()
7398 {
7399 shared int[int] map;
7400 map[1] = 1;
7401 }
7402
7403 /***************************************************/
7404 // 13720
7405
7406 struct FracSec13720
7407 {
7408 this(int hnsecs) {}
7409 }
7410
7411 struct SysTime13720
7412 {
7413 this(TimeOfDay13720 dateTime, FracSec13720 fracSec)
7414 {
7415 }
7416 }
7417
7418 struct TimeOfDay13720
7419 {
7420 ~this() { }
7421 }
7422
7423 void assertThrown13720(T)(lazy T) {}
7424
7425 void test13720()
7426 {
7427 assertThrown13720(SysTime13720(TimeOfDay13720.init, FracSec13720(-1)));
7428 }
7429
7430 /***************************************************/
7431 // 13952
7432
7433 struct Reg13952
7434 {
7435 ubyte type;
7436 ubyte regNo;
7437 ushort size;
7438 }
7439
7440 struct Imm13952
7441 {
7442 ulong imm;
7443 }
7444
7445 struct Opnd13952
7446 {
7447 union
7448 {
7449 Reg13952 reg; // size == 4
7450 Imm13952 imm; // size == 8
7451 }
7452 ubyte tag;
7453
7454 this(Reg13952 r) { reg = r; }
7455 }
7456
7457 Opnd13952 opnd13952(Reg13952 reg)
7458 {
7459 return Opnd13952(reg);
7460 }
7461
7462 void test13952()
7463 {
7464 Reg13952 reg;
7465 auto op = opnd13952(reg);
7466 auto buf = (cast(ubyte*)&op)[0 .. op.sizeof];
7467 //debug
7468 //{
7469 // import std.stdio;
7470 // writefln("op.reg = [%(%02x %)]", (cast(ubyte*)&op.reg)[0 .. Reg13952.sizeof]);
7471 // writefln("op.imm = [%(%02x %)]", (cast(ubyte*)&op.imm)[0 .. Imm13952.sizeof]);
7472 //}
7473 foreach (e; buf) assert(e == 0);
7474 }
7475
7476 /***************************************************/
7477 // 14165
7478
7479 class Foo14165
7480 {
7481 @disable this();
7482 this(int i) {}
7483 }
7484
7485 /***************************************************/
7486 // 13985
7487
7488 interface I13985
7489 {
7490 void m1();
7491 void m2();
7492 void m3();
7493
7494 final void mf()
7495 {
7496 m3();
7497 }
7498 }
7499
7500 class C13985 : I13985
7501 {
7502 void m1() {}
7503 void m2() {}
7504 void m3() {}
7505 }
7506
7507 class D13985 : C13985
7508 {
7509 void ml()
7510 {
7511 super.mf();
7512 }
7513 }
7514
7515 void test13985()
7516 {
7517 auto d = new D13985();
7518 d.ml();
7519 }
7520
7521 /***************************************************/
7522 // 14211
7523
7524 extern(C++) // all derived classes won't have invariants
7525 class B14211
7526 {
7527 void func()
7528 {
7529 }
7530 }
7531
7532 final class C14211 : B14211
7533 {
7534 }
7535
7536 void test14211()
7537 {
7538 auto c = new C14211();
7539 *cast(void**)c = null;
7540 c.func(); // called without vtbl access
7541 }
7542
7543 /***************************************************/
7544 // 14552
7545
7546 template map14552(fun...)
7547 {
7548 template AppliedReturnType(alias f)
7549 {
7550 alias typeof(f(0)) AppliedReturnType;
7551 }
7552
7553 auto map14552(int[] r)
7554 {
7555 assert(!is(AppliedReturnType!fun));
7556 return MapResult14552!fun();
7557 }
7558 }
7559
7560 struct MapResult14552(alias fun)
7561 {
7562 @property front()
7563 {
7564 fun(0);
7565 }
7566 }
7567
7568 class Outer14552
7569 {
7570 auto test()
7571 {
7572 [1].map14552!(j => new Inner);
7573 }
7574 class Inner {}
7575 }
7576
7577 /***************************************************/
7578 // 14853
7579
7580 struct Queue14853(T)
7581 {
7582 struct Node
7583 {
7584 T mfPayload = T.init;
7585 union
7586 {
7587 typeof(this)* mfPrev;
7588 shared(typeof(this)*) mfShPrev;
7589 }
7590 union
7591 {
7592 typeof(this)* mfNext;
7593 shared(typeof(this)*) mfShNext;
7594 }
7595 }
7596
7597 Node root;
7598
7599 void pfPut(T v, Node* r = null)
7600 {
7601 shared n = new Node(v); // problem!
7602 }
7603 }
7604
7605 void test14853()
7606 {
7607 auto b1 = new Queue14853!uint;
7608 }
7609
7610 /********************************************************/
7611 // 15045
7612
7613 void test15045()
7614 {
7615 void testName(T, bool r, string name)()
7616 {
7617 T t;
7618
7619 static assert(r == is(typeof(mixin("T."~name))));
7620 static assert(r == is(typeof(mixin("t."~name))));
7621 static assert(r == __traits(compiles, mixin("T."~name)));
7622 static assert(r == __traits(compiles, mixin("t."~name)));
7623 static assert(r == mixin("__traits(compiles, T."~name~")"));
7624 static assert(r == mixin("__traits(compiles, t."~name~")"));
7625
7626 static assert(r == __traits(hasMember, T, name) );
7627 static assert(r == __traits(hasMember, t, name) );
7628 static assert(r == __traits(compiles, __traits(getMember, T, name) ));
7629 static assert(r == __traits(compiles, __traits(getMember, t, name) ));
7630 static assert(r == __traits(compiles, __traits(getOverloads, T, name) ));
7631 static assert(r == __traits(compiles, __traits(getOverloads, t, name) ));
7632 }
7633 void test(T, bool r)()
7634 {
7635 testName!(T, r, "__ctor")();
7636 testName!(T, r, "__dtor")();
7637 testName!(T, r, "__xdtor")();
7638 testName!(T, r, "__postblit")();
7639 testName!(T, r, "__xpostblit")();
7640 }
7641
7642 static struct X
7643 {
7644 this(int) {}
7645 this(this) {}
7646 ~this() {}
7647 }
7648
7649 static struct S1
7650 {
7651 auto opDispatch(string name, A...)(A args) { }
7652 }
7653 static struct S2
7654 {
7655 X get() { return X(); };
7656 alias get this;
7657 }
7658 static struct S3
7659 {
7660 X opDot() { return X(); };
7661 }
7662
7663 test!(X, true)();
7664 test!(S1, false)();
7665 test!(S2, false)();
7666 test!(S3, false)();
7667 }
7668
7669 /***************************************************/
7670 // 15116
7671
7672 alias TypeTuple15116(T...) = T;
7673
7674 template Mix15116()
7675 {
7676 TypeTuple15116!(int, int) tup;
7677 }
7678
7679 struct S15116
7680 {
7681 mixin Mix15116 mix;
7682 }
7683
7684 void test15116()
7685 {
7686 S15116 s;
7687 auto x1 = s.tup; // OK
7688 auto x2 = s.mix.tup; // OK <- NG
7689 }
7690
7691 /***************************************************/
7692 // 15117
7693
7694 template Mix15117()
7695 {
7696 int y = { typeof(this)* s; return s ? s.mix.y : 0; }();
7697 }
7698
7699 struct S15117
7700 {
7701 int x = { typeof(this)* s; return s ? s.x : 0; }(); // OK
7702
7703 mixin Mix15117 mix; // OK <- NG
7704 }
7705
7706 /***************************************************/
7707 // 15126
7708
7709 struct Json15126
7710 {
7711 ubyte[16] m_data;
7712 int opDispatch(string prop)() const { return 0; }
7713 int opDispatch(string prop)() { return 0; }
7714 }
7715
7716 template isCustomSerializable15126(T)
7717 {
7718 enum isCustomSerializable15126 = T.init.toRepresentation();
7719 }
7720
7721 alias bug15126 = isCustomSerializable15126!Json15126;
7722
7723 /***************************************************/
7724 // 15141
7725
7726 class A15141
7727 {
7728 abstract void method();
7729 }
7730
7731 class B15141 : A15141 { }
7732
7733 void test15141()
7734 {
7735 auto a = Object.factory(__MODULE__ ~ ".A15141");
7736 assert(a is null);
7737 auto b = Object.factory(__MODULE__ ~ ".B15141");
7738 assert(b is null); // OK <- oops
7739 }
7740
7741 /***************************************************/
7742 // 15366
7743
7744 enum E15366 : bool { A, B };
7745
7746 struct S15366
7747 {
7748 void func1(E15366 e) {}
7749
7750 void func2(E15366 a, E15366 b)
7751 {
7752 func1(cast(E15366)(a && b));
7753 func1(cast(E15366)(a || b));
7754
7755 auto x1 = cast(E15366)(a && b);
7756 auto x2 = cast(E15366)(a || b);
7757 }
7758 }
7759
7760 /***************************************************/
7761 // 15369
7762
7763 struct MsgTable15369
7764 {
7765 const(char)[] ident;
7766 const(char)* name;
7767 };
7768
7769 MsgTable15369[] msgTable15369 =
7770 [
7771 { "empty", "" },
7772 ];
7773
7774 void test15369()
7775 {
7776 auto id = msgTable15369[0].ident;
7777 auto p = msgTable15369[0].name;
7778
7779 // a string literal "" should be zero-terminated
7780 assert(*p == '\0');
7781 }
7782
7783 void test15638()
7784 {
7785 class A {}
7786 class B : A {}
7787 class C : A {}
7788
7789 B b;
7790 C c;
7791 const(B) cb;
7792 const(C) cc;
7793 immutable(B) ib;
7794 immutable(C) ic;
7795
7796 // Common type for const derived classes
7797 auto constCommon = true ? cb : cc;
7798 static assert(is(typeof(constCommon) == const(A)));
7799
7800 // Common type for immutable derived classes
7801 auto immutableCommon = true ? ib : ic;
7802 static assert(is(typeof(immutableCommon) == immutable(A)));
7803
7804 // Common type for mixed const/immutable derived classes
7805 auto mixed1 = true ? cb : ic;
7806 static assert(is(typeof(mixed1) == const(A)));
7807 auto mixed2 = true ? ib : cc;
7808 static assert(is(typeof(mixed2) == const(A)));
7809
7810 // Common type for mixed mutable/immutable derived classes
7811 auto mixed3 = true ? b : ic;
7812 static assert(is(typeof(mixed3) == const(A)));
7813 auto mixed4 = true ? ib : c;
7814 static assert(is(typeof(mixed4) == const(A)));
7815
7816 // Array literal type deduction
7817 auto arr1 = [ new immutable(B), new C ];
7818 auto arr2 = [ new B, new const(C) ];
7819 auto arr3 = [ new immutable(B), new immutable(C) ];
7820 static assert(is(typeof(arr1) == const(A)[]));
7821 static assert(is(typeof(arr2) == const(A)[]));
7822 static assert(is(typeof(arr3) == immutable(A)[]));
7823 }
7824
7825 /***************************************************/
7826 // 15961
7827
7828 struct SliceOverIndexed15961(T)
7829 {
7830 enum assignableIndex = T.init;
7831 }
7832
7833 struct Grapheme15961
7834 {
7835 SliceOverIndexed15961!Grapheme15961 opSlice()
7836 {
7837 assert(0);
7838 }
7839
7840 struct
7841 {
7842 ubyte* ptr_;
7843 }
7844 }
7845
7846 /***************************************************/
7847 // 16022
7848
7849 bool test16022()
7850 {
7851 enum Type { Colon, Comma }
7852 Type type;
7853 return type == Type.Colon, type == Type.Comma;
7854 }
7855
7856 /***************************************************/
7857 // https://issues.dlang.org/show_bug.cgi?id=16233
7858
7859 enum valueConvertible(T1, T2) = blah;
7860
7861 struct Checked(T, Hook)
7862 {
7863 bool opEquals(U)(Checked!(U, Hook) rhs)
7864 {
7865 alias R = typeof(payload + rhs.payload);
7866 static if (valueConvertible!(T, R))
7867 {
7868 }
7869 return false;
7870 }
7871 }
7872
7873 void test16233()
7874 {
7875 Checked!(Checked!(int, void), void) x1;
7876 }
7877
7878 /***************************************************/
7879 // https://issues.dlang.org/show_bug.cgi?id=16466
7880
7881 void test16466()
7882 {
7883 static struct S
7884 {
7885 real r;
7886 }
7887 real r;
7888 printf("S.alignof: %x, r.alignof: %x\n", S.alignof, r.alignof);
7889 assert(S.alignof == r.alignof);
7890 }
7891
7892 /***************************************************/
7893
7894 // https://issues.dlang.org/show_bug.cgi?id=16408
7895
7896 char[1] SDL_GetKeyName_buffer;
7897
7898 const(char)[] SDL_GetKeyName(char k)
7899 {
7900 pragma(inline, false);
7901 SDL_GetKeyName_buffer[0] = k;
7902 return SDL_GetKeyName_buffer[];
7903 }
7904
7905 void formattedWrite(const(char)[] strW, const(char)[] strA, const(char)[] strC)
7906 {
7907 pragma(inline, false);
7908
7909 assert(strW == "W");
7910 assert(strA == "A");
7911 assert(strC == "C");
7912 }
7913
7914 void test16408()
7915 {
7916 pragma(inline, false);
7917 formattedWrite(
7918 SDL_GetKeyName('W').idup,
7919 SDL_GetKeyName('A').idup,
7920 SDL_GetKeyName('C').idup
7921 );
7922 }
7923
7924 /***************************************************/
7925 // https://issues.dlang.org/show_bug.cgi?id=17349
7926
7927 void test17349()
7928 {
7929 static struct S
7930 {
7931 int bar(void delegate(ref int*)) { return 1; }
7932 int bar(void delegate(ref const int*)) const { return 2; }
7933 }
7934
7935 void dg1(ref int*) { }
7936 void dg2(ref const int*) { }
7937 S s;
7938 int i;
7939 i = s.bar(&dg1);
7940 assert(i == 1);
7941 i = s.bar(&dg2);
7942 assert(i == 2);
7943 }
7944
7945 /***************************************************/
7946 // https://issues.dlang.org/show_bug.cgi?id=17915
7947
7948 void test17915()
7949 {
7950 static class MyClass
7951 {
7952 S17915!MyClass m_member;
7953 }
7954 }
7955
7956 struct S17915(T)
7957 {
7958 T owner;
7959 }
7960
7961 /***************************************************/
7962
7963 int main()
7964 {
7965 test1();
7966 test2();
7967 test3();
7968 test4();
7969 test5();
7970 test6();
7971 test7();
7972 test8();
7973 test9();
7974 test10();
7975 test11();
7976 test12();
7977 test13();
7978 test14();
7979 test15();
7980 test16();
7981 test17();
7982 test18();
7983 test19();
7984 test20();
7985 test21();
7986 test22();
7987 test23();
7988 test24();
7989 test25();
7990 test26();
7991 test27();
7992 test28();
7993 test29();
7994 test30();
7995 test31();
7996 test32();
7997 test33();
7998 test34();
7999 test35();
8000 test36();
8001 test37();
8002 test38();
8003 test39();
8004 test40();
8005 test41();
8006 test42();
8007 test43();
8008 test44();
8009 test45();
8010 test46();
8011 test47();
8012 test48();
8013 test49();
8014 test796();
8015 test50();
8016 test51();
8017 test52();
8018 test53();
8019 test54();
8020 test55();
8021 test56();
8022 test57();
8023 test58();
8024
8025 test60();
8026 test61();
8027 test62();
8028 test63();
8029 test64();
8030 test65();
8031 test66();
8032 test67();
8033 test68();
8034 test69();
8035 test70();
8036
8037 test5785();
8038 test72();
8039 test73();
8040 test74();
8041 test75();
8042 test76();
8043 test77();
8044 test78();
8045 test79();
8046 test80();
8047 test81();
8048 test82();
8049 test83();
8050 test3559();
8051 test84();
8052 test85();
8053 test2006();
8054 test8442();
8055 test86();
8056 test87();
8057 test2486();
8058 test5554();
8059 test88();
8060 test7545();
8061 test89();
8062 test90();
8063 test91();
8064 test92();
8065 test4536();
8066 test93();
8067 test94();
8068 test95();
8069 test5403();
8070 test96();
8071 test97();
8072 test98();
8073 test99();
8074 test100();
8075 test101();
8076
8077 test103();
8078 test104();
8079 test105();
8080 test3927();
8081 test107();
8082
8083 test109();
8084
8085 test111();
8086
8087 test113();
8088
8089 test115();
8090 test116();
8091 test117();
8092 test3822();
8093 test6545();
8094 test118();
8095 test5081();
8096
8097 test120();
8098 test10724();
8099 test122();
8100 test123();
8101 test124();
8102 test125();
8103 test6763();
8104
8105 test127();
8106 test128();
8107 test1891();
8108 test129();
8109 test130();
8110 test1064();
8111 test131();
8112 test132();
8113 test133();
8114 test134();
8115 test135();
8116 test136();
8117 test137();
8118 test138();
8119 test1962();
8120 test139();
8121 test140();
8122 test141();
8123 test6317();
8124 test142();
8125 test143();
8126 test144();
8127 test145();
8128 test146();
8129 test147();
8130 test6685();
8131 test148();
8132 test149();
8133 test2356();
8134 test13652();
8135 test11238();
8136 test2540();
8137 test14348();
8138 test150();
8139 test151();
8140 test152();
8141 test153();
8142 test154();
8143 test155();
8144 test156();
8145 test658();
8146 test4258();
8147 test4539();
8148 test4963();
8149 test4031();
8150 test5437();
8151 test6230();
8152 test6264();
8153 test6284();
8154 test6295();
8155 test6293();
8156 test5046();
8157 test1471();
8158 test6335();
8159 test1687();
8160 test6228();
8161 test3733();
8162 test4392();
8163 test7942();
8164 test6220();
8165 test5799();
8166 test157();
8167 test6473();
8168 test6630();
8169 test6690();
8170 test2953();
8171 test2997();
8172 test4423();
8173 test4647();
8174 test5696();
8175 test6084();
8176 test6488();
8177 test6565();
8178 test6836();
8179 test6837();
8180 test6927();
8181 test6733();
8182 test6813();
8183 test6859();
8184 test3022();
8185 test6910();
8186 test6902();
8187 test6330();
8188 test6868();
8189 test2856();
8190 test3091();
8191 test6056();
8192 test6356();
8193 test7073();
8194 test7104();
8195 test7150();
8196 test7160();
8197 test7168();
8198 test7170();
8199 test7196();
8200 test7285();
8201 test14737();
8202 test7321();
8203 test3282();
8204 test7534();
8205 test7534cov();
8206 test7618();
8207 test7621();
8208 test11417();
8209 test7682();
8210 test7735();
8211 test7823();
8212 test7871();
8213 test7906();
8214 test7907();
8215 test12503();
8216 test8004();
8217 test8064();
8218 test8105();
8219 test159();
8220 test12824();
8221 test8283();
8222 test13182();
8223 test8269();
8224 test8395();
8225 test13427();
8226 test5749();
8227 test8396();
8228 test160();
8229 test8665();
8230 test8108();
8231 test8360();
8232 test9577();
8233 test6141();
8234 test199();
8235 test8526();
8236 test161();
8237 test7175();
8238 test8819();
8239 test8917();
8240 test8945();
8241 test11805();
8242 test14192();
8243 test163();
8244 test9428();
8245 test9477();
8246 test9538();
8247 test9700();
8248 test9834();
8249 test13947();
8250 test9883();
8251 test10091();
8252 test9130();
8253 test10542();
8254 test10539();
8255 test10634();
8256 test15080();
8257 test7254();
8258 test13468();
8259 test11075();
8260 test11181();
8261 test11317();
8262 test11888();
8263 test12036();
8264 test12153();
8265 test12937();
8266 test13154();
8267 test13437();
8268 test13472();
8269 test13476();
8270 test13720();
8271 test13952();
8272 test13985();
8273 test14211();
8274 test15141();
8275 test15369();
8276 test15638();
8277 test16233();
8278 test16466();
8279 test16408();
8280 test17349();
8281 test17915();
8282
8283 printf("Success\n");
8284 return 0;
8285 }
8286