1 // RUNNABLE_PHOBOS_TEST
2 module test;
3
4 import core.vararg;
5 import std.stdio;
6 import std.string;
7
8 extern(C) int printf(const char*, ...);
9
10 /*******************************************/
11
12 struct S1
13 {
14 void* function(void*) fn;
15 }
16
M1()17 template M1()
18 {
19 S1 s;
20 }
21
test1()22 void test1()
23 {
24 S1 s2;
25 mixin M1;
26 assert(s.fn == null);
27 }
28
29 /*******************************************/
30
31 enum Qwert { yuiop }
32
asdfg(Qwert hjkl)33 int asdfg(Qwert hjkl) { return 1; }
asdfg(uint zxcvb)34 int asdfg(uint zxcvb) { return 2; }
35
test2()36 void test2()
37 {
38 int nm = 2;
39
40 assert(asdfg(nm) == 2);
41 assert(asdfg(cast(int) nm) == 2);
42 assert(asdfg(3) == 2);
43 assert(asdfg(cast(int) 3) == 2);
44 assert(asdfg(3L) == 2);
45 assert(asdfg(cast(int) 3L) == 2);
46 assert(asdfg(3 + 2) == 2);
47 assert(asdfg(cast(int) (3 + 2)) == 2);
48 assert(asdfg(nm + 2) == 2);
49 assert(asdfg(cast(int) (nm + 2)) == 2);
50 assert(asdfg(3 + nm) == 2);
51 assert(asdfg(cast(int) (3 + nm)) == 2);
52
53 }
54
55 /*******************************************/
56
Qwert3(string yuiop)57 template Qwert3(string yuiop) {
58 immutable string Qwert3 = cast(string)yuiop;
59 }
60
Asdfg3(string yuiop)61 template Asdfg3(string yuiop) {
62 immutable string Asdfg3 = cast(string)Qwert3!(cast(string)(cast(string)yuiop ~ cast(string)"hjkl"));
63 }
64
test3()65 void test3()
66 {
67 string zxcvb = Asdfg3!(null);
68 assert(zxcvb == "hjkl");
69 assert(zxcvb == "hjkl" ~ null);
70 }
71
72 /*******************************************/
73
Qwert4(string yuiop)74 template Qwert4(string yuiop)
75 {
76 immutable string Qwert4 = cast(string)(yuiop ~ "asdfg" ~ yuiop);
77 }
78
test4()79 void test4()
80 {
81 string hjkl = Qwert4!(null);
82 assert(hjkl == "asdfg");
83 }
84
85 /*******************************************/
86
test6()87 void test6()
88 {
89 struct Foo
90 {
91 void foo() { }
92 }
93
94 alias Foo Bar;
95
96 Bar a;
97 a.foo();
98 }
99
100 /*******************************************/
101
test7()102 void test7()
103 {
104 struct Foo
105 {
106 alias typeof(this) ThisType;
107 alias typeof(this) ThatType;
108 }
109
110 assert(is(Foo.ThisType == Foo));
111 assert(is(Foo.ThatType == Foo));
112 }
113
114 /*******************************************/
115
test8()116 void test8()
117 {
118 int[] test;
119 test.length = 10;
120 // Show address of array start and its length (10)
121 writefln("%s %s", cast(uint)test.ptr, test.length);
122
123 test.length = 1;
124 // Show address of array start and its length (1)
125 writefln("%s %s", cast(uint)test.ptr, test.length);
126
127 test.length = 8;
128 // Show address of array start and its length (8)
129 writefln("%s %s", cast(uint)test.ptr, test.length);
130
131 test.length = 0;
132 // Shows 0 and 0!
133 writefln("%s %s", cast(uint)test.ptr, test.length);
134 assert(test.length == 0);
135 assert(test.ptr != null);
136 }
137
138 /*******************************************/
139
140 cdouble y9;
141
f9(cdouble x)142 cdouble f9(cdouble x)
143 {
144 return (y9 = x);
145 }
146
test9()147 void test9()
148 {
149 f9(1.0+2.0i);
150 assert(y9 == 1.0+2.0i);
151 }
152
153 /*******************************************/
154
155 class CBase10
156 {
this()157 this() { }
158 }
159
foo10(CBase10 l)160 void foo10( CBase10 l )
161 {
162 }
163
test10()164 void test10()
165 {
166 if (1)
167 {
168 foo10( new class() CBase10
169 {
170 this() { super(); }
171 }
172 );
173 }
174 return;
175 }
176
177 /*******************************************/
178
179 struct Foo11
180 {
181 static
funcFoo11182 int func(T)(T a) { assert(a == 1); return 0; }
183 }
184
test11()185 void test11()
186 {
187 auto a = Foo11.init.func(1);
188 a = Foo11.init.func!(int)(1);
189 a = Foo11.func(1);
190 a = Foo11.func!(int)(1);
191 }
192
193 /*******************************************/
194
test12()195 void test12()
196 {
197 class ExceptioN { }
198
199 class ExceptioX { }
200
201 static assert(ExceptioN.mangleof[0 ..$-1] == ExceptioX.mangleof[0 .. $-1]);
202 }
203
204 /*******************************************/
205
check(char ch1,char ch2)206 template check( char ch1, char ch2)
207 {
208 const bool check = ch1 == ch2;
209 }
210
test13()211 void test13()
212 {
213 const char[] s = "123+456" ;
214 assert(check!( '+', s[3] ) == true);
215 }
216
217 /*******************************************/
218
test14()219 void test14()
220 {
221 static const char[] test=['a','b','c','d'];
222 static assert(test==['a','b','c','d']);
223 static assert(['a','b','c','d']== test);
224 }
225
226 /*******************************************/
227
func15(...)228 void func15(...)
229 in {
230 writefln("Arguments len = %d\n", _arguments.length);
231 assert(_arguments.length == 2);
232 }
233 body {
234
235 }
236
test15()237 void test15()
238 {
239 func15(1, 2);
240 }
241
242 /*******************************************/
243
test17()244 void test17()
245 {
246 void delegate() y = { };
247 y();
248 }
249
250 /*******************************************/
251
252 abstract class Pen { int foo(); }
253
254 class Penfold : Pen {
foo()255 override int foo() { return 1; }
256 }
257
258 class Pinky : Pen {
foo()259 override int foo() { return 2; }
260 }
261
262 class Printer {
vprint(Pen obj)263 void vprint(Pen obj) {
264 assert(obj.foo() == 1 || obj.foo() == 2);
265 }
266
print(C)267 C print(C)(C obj) {
268 assert(obj.foo() == 1 || obj.foo() == 2);
269 return obj;
270 }
271
272 }
273
test18()274 void test18()
275 {
276 Printer p = new Printer;
277 p.print(new Pinky);
278 p.print(new Penfold);
279 with (p)
280 {
281 vprint(new Pinky);
282 vprint(new Penfold);
283
284 print!(Pinky)(new Pinky);
285 print!(Penfold)(new Penfold);
286
287 p.print(new Pinky);
288 p.print(new Penfold);
289
290 print(new Pinky);
291 print(new Penfold);
292 }
293 }
294
295 /*******************************************/
296
297
298 class A19
299 {
s()300 void s() {}
301 }
302
303 class B19 : A19
304 {
305 alias A19.s s;
s(int i)306 static void s(int i) {}
s()307 override void s() {}
308 }
309
310 class C19
311 {
f()312 void f() {
313 B19.s(0);
314 }
315 }
316
test19()317 void test19()
318 {
319 }
320
321
322 /*******************************************/
323
324 class U {}
325 class T : U {}
326
test20()327 void test20()
328 {
329 T* ptr;
330 T[2] sar;
331 T[] dar;
332
333 // all of the following should work according to the "Implicit
334 // Conversions" section of the spec
335
336 tPtr(ptr);
337 tPtr(sar.ptr);
338 tPtr(dar.ptr);
339 tDar(sar);
340
341 // uPtr(ptr); // T* => U*
342 // uPtr(sar); // T[2] => U*
343 // uPtr(dar); // T[] => U*
344 // uSar(sar); // T[2] => U[2]
345 // uDar(sar); // T[2] => U[]
346
347 uDar(dar); // T[] => const(U)[]
348 vPtr(ptr); // T* => void*
349 vPtr(sar.ptr);
350 vPtr(dar.ptr);
351
352 vDar(sar);
353 vDar(dar); // works, but T[] => void[] isn't mentioned in the spec
354 }
355
tPtr(T * t)356 void tPtr(T*t){}
tDar(T[]t)357 void tDar(T[]t){}
uPtr(U * u)358 void uPtr(U*u){}
uSar(U[2]u)359 void uSar(U[2]u){}
uDar(const (U)[]u)360 void uDar(const(U)[]u){}
vPtr(void * v)361 void vPtr(void*v){}
vDar(void[]v)362 void vDar(void[]v){}
363
364
365 /*******************************************/
366
367 struct Foo21
368 {
369 int i;
370 }
371
some_struct_instance(T)372 template some_struct_instance(T)
373 {
374 static Foo21 some_struct_instance =
375 {
376 5,
377 };
378 }
379
test21()380 void test21()
381 {
382 alias some_struct_instance!(int) inst;
383 assert(inst.i == 5);
384 }
385
386 /*******************************************/
387
Foo22(T)388 struct Foo22(T) {}
389
test22()390 void test22()
391 {
392 int i;
393
394 if ((Foo22!(char)).init == (Foo22!(char)).init)
395 i = 1;
396 assert(i == 1);
397 }
398
399
400 /*******************************************/
401
test23()402 void test23()
403 {
404 auto t=['a','b','c','d'];
405 writeln(typeid(typeof(t)));
406 assert(is(typeof(t) == char[]));
407
408 const t2=['a','b','c','d','e'];
409 writeln(typeid(typeof(t2)));
410 assert(is(typeof(t2) == const(const(char)[])));
411 }
412
413 /*******************************************/
414
foo24(int i...)415 int foo24(int i ...)
416 {
417 return i;
418 }
419
test24()420 void test24()
421 {
422 assert(foo24(3) == 3);
423 }
424
425 /*******************************************/
426
test25()427 void test25()
428 {
429 ireal x = 4.0Li;
430 ireal y = 4.0Li;
431 ireal z = 4Li;
432 creal c = 4L + 0Li;
433 }
434
435 /*******************************************/
436
437 struct Foo26
438 {
439 int a;
440
opCallFoo26441 static Foo26 opCall(int i)
442 { Foo26 f;
443 f.a += i;
444 return f;
445 }
446 }
447
test26()448 void test26()
449 { Foo26 f;
450
451 f = cast(Foo26)3;
452 assert(f.a == 3);
453
454 Foo26 g = 3;
455 assert(g.a == 3);
456 }
457
458 /*******************************************/
459
460 struct S27
461 {
462 int x;
463
opAssignS27464 void opAssign(int i)
465 {
466 x = i + 1;
467 }
468 }
469
test27()470 void test27()
471 {
472 S27 s;
473 s = 1;
474 assert(s.x == 2);
475 }
476
477 /*******************************************/
478
479 class C28
480 {
481 int x;
482
opAssign(int i)483 void opAssign(int i)
484 {
485 x = i + 1;
486 }
487 }
488
test28()489 void test28()
490 {
491 // No longer supported for 2.0
492 // C28 s = new C28;
493 // s = 1;
494 // assert(s.x == 2);
495 }
496
497 /*******************************************/
498
499 struct S29
500 {
opCallS29501 static S29 opCall(int v)
502 {
503 S29 result;
504 result.v = v;
505 return result;
506 }
507 int a;
508 int v;
509 int x,y,z;
510 }
511
foo29()512 int foo29()
513 {
514 auto s = S29(5);
515 return s.v;
516 }
517
test29()518 void test29()
519 {
520 int i = foo29();
521 printf("%d\n", i);
522 assert(i == 5);
523 }
524
525 /*******************************************/
526
527 struct S30
528 {
opCallS30529 static S30 opCall(int v)
530 {
531 S30 result;
532
533 void bar()
534 {
535 result.v += 1;
536 }
537
538 result.v = v;
539 bar();
540 return result;
541 }
542 int a;
543 int v;
544 int x,y,z;
545 }
546
foo30()547 int foo30()
548 {
549 auto s = S30(5);
550 return s.v;
551 }
552
test30()553 void test30()
554 {
555 int i = foo30();
556 printf("%d\n", i);
557 assert(i == 6);
558 }
559
560 /*******************************************/
561
562 struct S31
563 {
abcS31564 static void abc(S31 *r)
565 {
566 r.v += 1;
567 }
568
opCallS31569 static S31 opCall(int v)
570 {
571 S31 result;
572
573 void bar()
574 {
575 abc(&result);
576 }
577
578 result.v = v;
579 bar();
580 return result;
581 }
582 int a;
583 int v;
584 int x,y,z;
585 }
586
foo31()587 int foo31()
588 {
589 auto s = S31(5);
590 return s.v;
591 }
592
test31()593 void test31()
594 {
595 int i = foo31();
596 printf("%d\n", i);
597 assert(i == 6);
598 }
599
600 /*******************************************/
601
602
603 struct T32
604 {
opApplyT32605 int opApply(int delegate(ref int i) dg)
606 {
607 int i;
608 return dg(i);
609 }
610 }
611
612 struct S32
613 {
abc(S32 * r)614 static void abc(S32 *r)
615 {
616 r.v += 1;
617 }
618
opCall(int v)619 static S32 opCall(int v)
620 {
621 S32 result;
622 T32 t;
623
624 result.v = v;
625 foreach (i; t)
626 {
627 result.v += 1;
628 break;
629 }
630 return result;
631 }
632 int a;
633 int v;
634 int x,y,z;
635 }
636
foo32()637 int foo32()
638 {
639 auto s = S32(5);
640 return s.v;
641 }
642
test32()643 void test32()
644 {
645 int i = foo32();
646 printf("%d\n", i);
647 assert(i == 6);
648 }
649
650 /*******************************************/
651
652 class Confectionary
653 {
this(int sugar)654 this(int sugar)
655 {
656 //if (sugar < 500)
657 // tastiness = 200;
658
659 //for (int i = 0; i < 10; ++i)
660 // tastiness = 300;
661
662 //int[] tastinesses_array;
663
664 //foreach (n; tastinesses_array)
665 // tastiness = n;
666
667 //int[int] tastinesses_aa;
668
669 //foreach (n; tastinesses_aa)
670 // tastiness = n;
671
672 tastiness = 1;
673 }
674
675 const int tastiness;
676 }
677
test33()678 void test33()
679 {
680 }
681
682 /*******************************************/
683
a34(string name,T...)684 template a34(string name, T...)
685 {
686 string a34(string name,T t)
687 {
688 string localchar;
689 foreach (a34; T)
690 {
691 writefln(`hello`);
692 localchar ~= a34.mangleof;
693 }
694 return localchar;
695 }
696 }
697
test34()698 void test34()
699 {
700 writeln(a34!("Adf"[], typeof("adf"),uint)("Adf"[],"adf",1234));
701 }
702
703 /*******************************************/
704
a35(string name,T...)705 template a35(string name, T...)
706 {
707 int a35(M...)(M m)
708 {
709 return 3;
710 }
711 }
712
test35()713 void test35()
714 {
715 assert(a35!("adf")() == 3);
716 }
717
718 /*******************************************/
719
a36(AnotherT,string name,T...)720 template a36(AnotherT,string name,T...){
721 AnotherT a36(M...)(M){
722 AnotherT localchar;
723 foreach(a;T)
724 {
725 writefln(`hello`);
726 localchar~=a.mangleof;
727 }
728 return cast(AnotherT)localchar;
729 }
730 }
731
test36()732 void test36()
733 {
734 string b="adf";
735 uint i=123;
736 char[3] c="Adf";
737 writeln(a36!(typeof(b),"Adf")());
738 }
739
740 /*******************************************/
741
742 struct Q37 {
opCastQ37743 Y37 opCast() {
744 return Y37.init;
745 }
746 }
747
748 struct Y37 {
asdfg()749 Q37 asdfg() {
750 return Q37.init;
751 }
752
hjkl()753 void hjkl() {
754 Q37 zxcvb = asdfg(); // line 13
755 }
756 }
757
test37()758 void test37()
759 {
760 }
761
762 /*******************************************/
763
764
765
766 class C38 { }
767
foo38(C38[3]c)768 const(Object)[] foo38(C38[3] c) @system
769 { const(Object)[] x = c;
770 return x;
771 }
772
test38()773 void test38()
774 {
775 }
776
777 /*******************************************/
778
test39()779 void test39()
780 {
781 void print(string[] strs)
782 {
783 writeln(strs);
784 assert(format("%s", strs) == `["Matt", "Andrew"]`);
785 }
786
787 print(["Matt", "Andrew"]);
788 }
789
790 /*******************************************/
791
test40()792 void test40()
793 {
794 class C
795 {
796 Object propName()
797 {
798 return this;
799 }
800 }
801
802 auto c = new C;
803
804 with (c.propName)
805 {
806 writeln(toString());
807 }
808
809 auto foo = c.propName;
810 }
811
812 /*******************************************/
813
test41()814 void test41()
815 {
816 auto test = new char [2];
817
818 int x1, x2, x3;
819 char[] foo1() { x1++; return test; }
820 int foo2() { x2++; return 0; }
821 int foo3() { x3++; return 1; }
822
823 test [] = 'a';
824 test = test [0 .. 1];
825
826 foo1() [foo2() .. foo3()] = 'b';
827 assert(x1 == 1);
828 assert(x2 == 1);
829 assert(x3 == 1);
830
831 //test [0 .. 2] = 'b'; // this line should assert
832 writef ("%s\n", test.ptr [0 .. 2]);
833 }
834
835 /*******************************************/
836
test42()837 void test42()
838 {
839 struct X { int x; }
840
841 X x;
842 assert(x.x == 0);
843 x = x.init;
844 assert(x.x == 0);
845 }
846
847 /*******************************************/
848
849 struct A43
850 {
851 static const MY_CONST_STRING = "hello";
852
fooA43853 void foo()
854 {
855 // This will either print garbage or throw a UTF exception.
856 // But if never_called() is commented out, then it will work.
857 writefln("%s", MY_CONST_STRING);
858 }
859 }
860
never_called43()861 void never_called43()
862 {
863 // This can be anything; there just needs to be a reference to
864 // A43.MY_CONST_STRING somewhere.
865 writefln("%s", A43.MY_CONST_STRING);
866 }
867
test43()868 void test43()
869 {
870 A43 a;
871 a.foo();
872 }
873
874 /*******************************************/
875
876 class A44
877 {
878 static const MY_CONST_STRING = "hello";
879
this()880 this()
881 {
882 // This will either print garbage or throw a UTF exception.
883 // But if never_called() is commented out, then it will work.
884 writefln("%s", MY_CONST_STRING);
885 }
886 }
887
never_called44()888 void never_called44()
889 {
890 // This can be anything; there just needs to be a reference to
891 // A44.MY_CONST_STRING somewhere.
892 writefln("%s", A44.MY_CONST_STRING);
893 }
894
test44()895 void test44()
896 {
897 A44 a = new A44();
898 }
899
900 /*******************************************/
901
902 class C45
903 {
func(lazy size_t x)904 void func(lazy size_t x)
905 {
906 (new C45).func(super.toHash());
907 }
908 }
909
test45()910 void test45()
911 {
912 }
913
914 /*******************************************/
915
T46(double v)916 template T46(double v)
917 {
918 double T46 = v;
919 }
920
test46()921 void test46()
922 {
923 double g = T46!(double.nan) + T46!(-double.nan);
924 }
925
926 /*******************************************/
927
test47()928 void test47()
929 {
930 uint* where = (new uint[](5)).ptr;
931
932 where[0 .. 5] = 1;
933 assert(where[2] == 1);
934 where[0 .. 0] = 0;
935 assert(where[0] == 1);
936 assert(where[2] == 1);
937 }
938
939 /*******************************************/
940
test48()941 void test48()
942 {
943 Object o = new Object();
944 printf("%.*s\n", typeof(o).classinfo.name.length, typeof(o).classinfo.name.ptr);
945 printf("%.*s\n", (typeof(o)).classinfo.name.length, (typeof(o)).classinfo.name.ptr);
946 printf("%.*s\n", (Object).classinfo.name.length, (Object).classinfo.name.ptr);
947 }
948
949 /*******************************************/
950
test49()951 void test49()
952 {
953 foo49();
954 }
955
foo49()956 void foo49()
957 {
958 char[] bar;
959 assert(true, bar ~ "foo");
960 }
961
962 /*******************************************/
963
test50()964 void test50()
965 {
966 foo50("foo");
967 }
968
foo50(string bar)969 void foo50(string bar)
970 {
971 assert(true, bar ~ "foo");
972 }
973
974 /*******************************************/
975
976 struct Foo51
977 {
opCallFoo51978 static Foo51 opCall()
979 {
980 return Foo51.init;
981 }
982 private char[] _a;
983 private bool _b;
984 }
985
test51()986 void test51()
987 {
988 }
989
990 /*******************************************/
991
A52(T...)992 template A52(T ...) { }
993 mixin A52!(["abc2", "def"]);
994
test52()995 void test52()
996 {
997 }
998
999 /*******************************************/
1000
1001 enum: int
1002 {
1003 AF_INET53 = 2,
1004 PF_INET53 = AF_INET53,
1005 }
1006
1007 enum: int
1008 {
1009 SOCK_STREAM53 = 1,
1010 }
1011
1012 struct sockaddr_in53
1013 {
1014 int sin_family = AF_INET53;
1015 }
1016
1017 enum AddressFamily53: int
1018 {
1019 INET = AF_INET53,
1020 }
1021
1022 enum SocketType53: int
1023 {
1024 STREAM = SOCK_STREAM53,
1025 }
1026
1027
1028 class Socket53
1029 {
this(AddressFamily53 af,SocketType53 type)1030 this(AddressFamily53 af, SocketType53 type)
1031 {
1032 }
1033 }
1034
test53()1035 void test53()
1036 {
1037 new Socket53(AddressFamily53.INET, SocketType53.STREAM);
1038 }
1039
1040 /*******************************************/
1041
test54()1042 void test54()
1043 {
1044 int[2][] a;
1045 a ~= [1,2];
1046 assert(a.length == 1);
1047 assert(a[0][0] == 1);
1048 assert(a[0][1] == 2);
1049 }
1050
1051 /*******************************************/
1052
test55()1053 void test55()
1054 {
1055 float[][] a = new float [][](1, 1);
1056
1057 if((a.length != 1) || (a[0].length != 1)){
1058 assert(0);
1059 }
1060 if (a[0][0] == a[0][0]){
1061 assert(0);
1062 }
1063 }
1064
1065 /*******************************************/
1066
test58()1067 void test58()
1068 {
1069 struct S
1070 {
1071 int i;
1072 int[4] bar = 4;
1073 float[4] abc;
1074 }
1075
1076 static S a = {i: 1};
1077 static S b;
1078
1079 writefln("a.bar: %s, %s", a.bar, a.abc);
1080 assert(a.i == 1);
1081 assert(a.bar[0] == 4);
1082 assert(a.bar[1] == 4);
1083 assert(a.bar[2] == 4);
1084 assert(a.bar[3] == 4);
1085 writefln("b.bar: %s, %s", b.bar, b.abc);
1086 assert(b.i == 0);
1087 assert(b.bar[0] == 4);
1088 assert(b.bar[1] == 4);
1089 assert(b.bar[2] == 4);
1090 assert(b.bar[3] == 4);
1091 }
1092
1093
1094 /*******************************************/
1095
bug59(string s)1096 void bug59(string s)()
1097 {
1098 writeln(s);
1099 writeln(s.length);
1100 }
1101
test59()1102 void test59()
1103 {
1104 bug59!("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234")();
1105 }
1106
1107 /*******************************************/
1108
Foo60(T)1109 class Foo60(T)
1110 {
1111 this() { unknown_identifier; }
1112 }
1113
test60()1114 void test60()
1115 {
1116 bool foobar = is( Foo60!(int) );
1117 assert(!foobar);
1118 }
1119
1120
1121 /*******************************************/
1122
repeat(int n,void delegate ()dg)1123 void repeat( int n, void delegate() dg )
1124 {
1125 printf("n = %d\n", n);
1126 if( n&1 ) dg();
1127 if( n/2 ) repeat( n/2, {dg();dg();} );
1128 }
1129
test61()1130 void test61()
1131 {
1132 repeat( 10, {printf("Hello\n");} );
1133 }
1134
1135 /*******************************************/
1136
test62()1137 void test62()
1138 {
1139 Vector62 a;
1140 a.set(1,2,24);
1141 a = a * 2;
1142 writeln(a.x, a.y, a.z);
1143 assert(a.x == 2);
1144 assert(a.y == 4);
1145 assert(a.z == 48);
1146 }
1147
1148
1149 struct Vector62
1150 {
1151 float x,y,z;
1152
1153 // constructor
setVector621154 void set(float _x, float _y, float _z)
1155 {
1156 x = _x;
1157 y = _y;
1158 z = _z;
1159 }
1160
opMulVector621161 Vector62 opMul(float s)
1162 {
1163 Vector62 ret;
1164 ret.x = x*s;
1165 ret.y = y*s;
1166 ret.z = z*s;
1167 return ret;
1168 }
1169 }
1170
1171 /*******************************************/
1172
1173 struct Data63
1174 {
1175 int x, y;
1176
1177 /// To make size > 8 so NRVO is used.
1178 /// Program runs correctly with this line commented out:
1179 byte filler;
1180 }
1181
frob(ref Data63 d)1182 Data63 frob(ref Data63 d)
1183 {
1184 Data63 ret;
1185 ret.y = d.x - d.y;
1186 ret.x = d.x + d.y;
1187 return ret;
1188 }
1189
test63()1190 void test63()
1191 {
1192 Data63 d; d.x = 1; d.y = 2;
1193 d = frob(d);
1194 writeln(d.x);
1195 writeln(d.y);
1196 assert(d.x == 3 && d.y == -1);
1197 }
1198
1199 /*******************************************/
1200
1201 class Foo64
1202 {
this()1203 this() { writefln("Foo64 created"); }
~this()1204 ~this() { writefln("Foo64 destroyed"); }
1205 }
1206
Mix64()1207 template Mix64()
1208 {
1209 void init() {
1210 ptr = new Foo64;
1211 }
1212 Foo64 ptr;
1213 }
1214
1215 class Container64
1216 {
this()1217 this() { init(); }
1218 mixin Mix64;
1219 }
1220
1221
test64()1222 void test64()
1223 {
1224 auto x = new Container64;
1225
1226 assert(!(x.classinfo.flags & 2));
1227 }
1228
1229 /*******************************************/
1230
Vector65(T,uint dim)1231 struct Vector65(T, uint dim)
1232 {
1233 T[dim] data;
1234 }
1235
dot65(T,uint dim)1236 T dot65(T, uint dim)(Vector65!(T,dim) a, Vector65!(T,dim) b)
1237 {
1238 T tmp;
1239 for ( int i = 0; i < dim; ++i )
1240 tmp += a.data[i] * b.data[i];
1241 return tmp;
1242 }
1243
test65()1244 void test65()
1245 {
1246 Vector65!(double,3u) a,b;
1247 auto t = dot65(a,b);
1248 }
1249
1250
1251 /*******************************************/
1252
main()1253 void main()
1254 {
1255 printf("Start\n");
1256
1257 test1();
1258 test2();
1259 test3();
1260 test4();
1261 test6();
1262 test7();
1263 test8();
1264 test9();
1265 test10();
1266 test11();
1267 test12();
1268 test13();
1269 test14();
1270 test15();
1271 test17();
1272 test18();
1273 test19();
1274 test20();
1275 test21();
1276 test22();
1277 test23();
1278 test24();
1279 test25();
1280 test26();
1281 test27();
1282 test28();
1283 test29();
1284 test30();
1285 test31();
1286 test32();
1287 test33();
1288 test34();
1289 test35();
1290 test36();
1291 test37();
1292 test38();
1293 test39();
1294 test40();
1295 test41();
1296 test42();
1297 test43();
1298 test44();
1299 test45();
1300 test46();
1301 test47();
1302 test48();
1303 test49();
1304 test50();
1305 test51();
1306 test52();
1307 test53();
1308 test54();
1309 test55();
1310 test58();
1311 test59();
1312 test60();
1313 test61();
1314 test62();
1315 test63();
1316 test64();
1317 test65();
1318
1319 printf("Success\n");
1320 }
1321
1322