1 /*
2 TEST_OUTPUT:
3 ---
4 const(immutable(char)*)
5 inout(immutable(char)*)
6 inout(const(char)*)
7 inout(const(char))
8 shared(inout(char))
9 shared(inout(char))
10 immutable(char)
11 immutable(char)
12 inout(const(char))
13 inout(const(char))
14 shared(const(char))
15 shared(const(char))
16 inout(char*****)
17 inout(char****)*
18 const(char*****)
19 const(char****)*
20 immutable(char*****)
21 immutable(char****)*
22 shared(char*****)
23 shared(char****)*
24 const(shared(char****)*)
25 shared(const(char*****))
26 shared(char*****)
27 immutable(char*****)
28 inout(shared(char****)*)
29 inout(shared(char**)***)
30 shared(inout(char**))
31 immutable(string)
32 const(char[])
33 char[]
34 shared(foo85)
35 const(char[26])
36 const(char[26])
37 immutable(char[26])
38 immutable(char[26])
39 string
40 int[3]
41 ---
42 */
43
44 import core.stdc.stdio;
45
46 class C { }
47
ctfe()48 int ctfe() { return 3; }
49
TypeTuple(T...)50 template TypeTuple(T...) { alias T TypeTuple; }
51
52 /************************************/
53
showf(string f)54 void showf(string f)
55 {
56 printf("%.*s\n", f.length, f.ptr);
57 }
58
59 /************************************/
60
test1()61 void test1()
62 {
63 const int* p;
64 const(int)* cp;
65 cp = p;
66 }
67
68 /************************************/
69
test2()70 void test2()
71 {
72 const int i = 3;
73 const(int) j = 0;
74 int k;
75 // j = i;
76 k = i;
77 k = j;
78 // assert(k == 3);
79 }
80
81 /************************************/
82
test3()83 void test3()
84 {
85 char[3] p;
86 const(char)[] q;
87
88 q = p;
89 }
90
91 /************************************/
92
test4()93 void test4()
94 {
95 char[] p;
96 const(char)[] q;
97
98 q = p;
99 }
100
101 /************************************/
102
test5()103 void test5()
104 {
105 const(int**)* p;
106 const(int)*** cp;
107 p = cp;
108 }
109
110 /************************************/
111
test6()112 void test6()
113 {
114 const(int***)[] p;
115 const(int)***[] cp;
116 p = cp;
117 }
118
119 /************************************/
120
121 class C8 { }
122
foo8(const char[]s,const C8 c,const int x)123 void foo8(const char[] s, const C8 c, const int x)
124 {
125 }
126
test8()127 void test8()
128 {
129 import core.demangle : demangle;
130 auto p = &foo8;
131 showf(p.mangleof);
132 assert(typeof(p).mangleof == "PFxAaxC9testconst2C8xiZv");
133 assert(demangle(p.mangleof) == "void function(const(char[]), const(testconst.C8), const(int))* testconst.test8().p");
134 }
135
136 /************************************/
137
test9()138 void test9()
139 {
140 int [ const (char[]) ] aa;
141 int [ char[] ] ab;
142 int [ const char[] ] ac;
143
144 aa["hello"] = 3;
145 ab["hello"] = 3;
146 ac["hello"] = 3;
147 }
148
149 /************************************/
150
test10()151 void test10()
152 {
153 const(int) x = 3;
154 auto y = x;
155 //y++;
156 assert(is(typeof(y) == const(int)));
157 }
158
159 /************************************/
160
foo11(in char[]a1)161 void foo11(in char[] a1)
162 {
163 char[3] c;
164 char[] a2 = c[];
165 a2[0..2] = a1;
166 a2[0..2] = 'c';
167
168 const char b = 'b';
169 a2[0..2] = b;
170 }
171
test11()172 void test11()
173 {
174 }
175
176 /************************************/
177
foo12(const char[]a1)178 void foo12(const char[] a1)
179 {
180 }
181
test12()182 void test12()
183 {
184 foo12("hello");
185 }
186
187 /************************************/
188
189 immutable char[16] hexdigits1 = "0123456789ABCDE1";
190 immutable char[ ] hexdigits2 = "0123456789ABCDE2";
191
192 const char[16] hexdigits3 = "0123456789ABCDE3";
193 const char[ ] hexdigits4 = "0123456789ABCDE4";
194
test13()195 void test13()
196 {
197 }
198
199 /************************************/
200
test14()201 void test14()
202 {
203 string s;
204 s = s ~ "hello";
205 }
206
207 /************************************/
208
209 class Foo15
210 {
211 const string xxxx;
212
this(immutable char[]aaa)213 this(immutable char[] aaa)
214 {
215 this.xxxx = aaa;
216 }
217 }
218
test15()219 void test15()
220 {
221 }
222
223 /************************************/
224
test16()225 void test16()
226 {
227 auto a = "abc";
228 immutable char[3] b = "abc";
229 const char[3] c = "abc";
230 }
231
232 /************************************/
233
test17()234 void test17()
235 {
236 const(char)[3][] a = (["abc", "def"]);
237
238 assert(a[0] == "abc");
239 assert(a[1] == "def");
240 }
241
242 /************************************/
243
244 class C18
245 {
foo()246 const(char)[] foo() { return "abc"; }
247 }
248
249 class D18 : C18
250 {
foo()251 override char[] foo() { return null; }
252 }
253
test18()254 void test18()
255 {
256 }
257
258 /************************************/
259
test19()260 void test19()
261 {
262 char[] s;
263 if (s == "abc")
264 s = null;
265 if (s < "abc")
266 s = null;
267 if (s is "abc")
268 s = null;
269 }
270
271 /************************************/
272
test20()273 void test20()
274 {
275 string p;
276 immutable char[] q;
277
278 p = p ~ q;
279 p ~= q;
280 }
281
282 /************************************/
283
test21()284 void test21()
285 {
286 string s;
287 char[] p;
288 p = s.dup;
289 }
290
291 /************************************/
292
fill22(const (char)[]s)293 void fill22(const(char)[] s)
294 {
295 }
296
test22()297 void test22()
298 {
299 }
300
301 /************************************/
302
303
304 struct S23
305 {
306 int x;
307 int* p;
308 }
309
310
foo23(const (S23)s,const (int)i)311 void foo23(const(S23) s, const(int) i)
312 {
313 immutable int j = 3;
314 // j = 4;
315 // i = 4;
316 // s.x = 3;
317 // *s.p = 4;
318 }
319
test23()320 void test23()
321 {
322 }
323
324 /************************************/
325
test24()326 void test24()
327 {
328 wchar[] r;
329
330 r ~= "\000"w;
331 }
332
333 /************************************/
334
test25()335 void test25()
336 {
337 char* p;
338 if (p == cast(const(char)*)"abc")
339 {}
340 }
341
342 /************************************/
343
test26()344 void test26()
345 {
346 struct S
347 {
348 char[3] a;
349 }
350
351 static S s = { "abc" };
352 }
353
354 /************************************/
355
356 class C27
357 {
358 int x;
359
foo()360 void foo() { x = 3; }
361 }
362
test27()363 void test27()
364 {
365 C27 d = new C27;
366 d.foo();
367 }
368
369 /************************************/
370
371 class C28
372 {
373 int x;
374
foo()375 void foo() immutable { }
376 }
377
test28()378 void test28()
379 {
380 immutable(C28) d = cast(immutable)new C28;
381 d.foo();
382 }
383
384 /************************************/
385
386 struct S29 { }
387
foo29(const (S29)* s)388 int foo29(const(S29)* s)
389 {
390 S29 s2;
391 return *s == s2;
392 }
393
test29()394 void test29()
395 {
396 }
397
398 /************************************/
399
400 struct S30
401 {
402 int x;
403
fooS30404 void foo() { x = 3; }
barS30405 void bar() const
406 { //x = 4;
407 //this.x = 5;
408 }
409 }
410
411 class C30
412 {
413 int x;
414
foo()415 void foo() { x = 3; }
bar()416 void bar() const
417 { //x = 4;
418 //this.x = 5;
419 }
420 }
421
test30()422 void test30()
423 { S30 s;
424
425 s.foo();
426 s.bar();
427
428 S30 t;
429 //t.foo();
430 t.bar();
431
432 C30 c = new C30;
433
434 c.foo();
435 c.bar();
436
437 C30 d = new C30;
438 d.foo();
439 d.bar();
440 }
441
442
443 /************************************/
444
445 class Foo31
446 {
447 int x;
448
immutable(int)449 immutable immutable(int)* geti()
450 {
451 return &x;
452 }
453
getc()454 const const(int)* getc()
455 {
456 return &x;
457 }
458 }
459
test31()460 void test31()
461 {
462 }
463
464 /************************************/
465
466 int bar32;
467
468 struct Foo32
469 {
funcFoo32470 int func() immutable
471 {
472 return bar32;
473 }
474 }
475
test32()476 void test32()
477 {
478 immutable(Foo32) foo;
479 printf("%d", foo.func());
480 printf("%d", foo.func());
481 }
482
483 /************************************/
484
test33()485 void test33()
486 {
487 string d = "a" ~ "b" ~ (1?"a":"");
488 assert(d == "aba");
489 }
490
491 /************************************/
492
493 struct S34
494 {
495 int value;
496 }
497
498 const S34 s34 = { 5 };
499
500 const S34 t34 = s34;
501 const S34 u34 = s34;
502
test34()503 void test34()
504 {
505 assert(u34.value == 5);
506 }
507
508 /************************************/
509
510 const int i35 = 20;
511
Foo35(alias bar)512 template Foo35(alias bar)
513 {
514 }
515
516 alias Foo35!(i35) foo35;
517
test35()518 void test35()
519 {
520 }
521
522 /************************************/
523
524 immutable char[10] digits = "0123456789"; /// 0..9
525 immutable char[] octdigits = digits[0 .. 8]; //// 0..7
526
test36()527 void test36()
528 {
529 }
530
531 /************************************/
532
test37()533 void test37()
534 {
535 int i = 3;
536 const int x = i;
537 i++;
538 assert(x == 3);
539 }
540
541 /************************************/
542
test38()543 void test38()
544 {
545 static const string s = "hello"[1..$];
546 assert(s == "ello");
547 }
548
549 /************************************/
550
551 static const int x39;
552 const int y39;
553
this()554 static this()
555 {
556 x39 = 3;
557 y39 = 4;
558 }
559
test39()560 void test39()
561 {
562 const int i;
563 assert(x39 == 3);
564 assert(y39 == 4);
565 const p = &x39;
566 // assert(*p == 3);
567 }
568
569 /************************************/
570
571 struct S40
572 {
573 int a;
574 const int b = 3; // shouldn't be allocated
575 }
576
test40()577 void test40()
578 {
579 assert(S40.sizeof == 8);
580 assert(S40.init.b == 3);
581 }
582
583 /************************************/
584
585 struct S41
586 {
587 int a;
588 const int b;
589 static const int c = ctfe() + 1;
590 }
591
test41()592 void test41()
593 {
594 assert(S41.sizeof == 8);
595 S41 s;
596 assert(s.b == 0);
597 assert(S41.c == 4);
598
599 const(int)*p;
600 p = &s.b;
601 assert(*p == 0);
602 p = &s.c;
603 assert(*p == 4);
604 }
605
606 /************************************/
607
608 class C42
609 {
610 int a = ctfe() - 2;
611 const int b;
612 const int c = ctfe();
613 static const int d;
614 static const int e = ctfe() + 2;
615
this()616 static this()
617 {
618 d = 4;
619 }
620
this()621 this()
622 {
623 b = 2;
624 }
625 }
626
test42()627 void test42()
628 {
629 printf("%d\n", C42.classinfo.initializer.length);
630 assert(C42.classinfo.initializer.length == 12 + (void*).sizeof +
631 (void*).sizeof);
632 C42 c = new C42;
633 assert(c.a == 1);
634 assert(c.b == 2);
635 assert(c.c == 3);
636 assert(c.d == 4);
637 assert(c.e == 5);
638
639 const(int)*p;
640 p = &c.b;
641 assert(*p == 2);
642 p = &c.c;
643 assert(*p == 3);
644 p = &c.d;
645 assert(*p == 4);
646 p = &c.e;
647 assert(*p == 5);
648 }
649
650 /************************************/
651
Foo43(T)652 template Foo43(T)
653 {
654 alias T Foo43;
655 }
656
test43()657 void test43()
658 {
659 {
660 int x;
661 alias Foo43!(typeof(x)) f;
662 showf(typeid(f).toString());
663 assert(is(typeof(x) == int));
664 assert(is(f == int));
665 }
666
667 {
668 const int x;
669 alias Foo43!(typeof(x)) f;
670 showf(typeid(f).toString());
671 assert(is(typeof(x) == const(int)));
672 assert(is(f == const(int)));
673 }
674
675 {
676 immutable int x;
677 alias Foo43!(typeof(x)) f;
678 showf(typeid(f).toString());
679 assert(is(typeof(x) == immutable(int)));
680 assert(is(f == immutable(int)));
681 }
682 }
683
684 /************************************/
685
686 template Foo44(T:T)
687 {
688 alias T Foo44;
689 }
690
test44()691 void test44()
692 {
693 {
694 int x;
695 alias Foo44!(typeof(x)) f;
696 showf(typeid(f).toString());
697 assert(is(typeof(x) == int));
698 assert(is(f == int));
699 }
700
701 {
702 const int x;
703 alias Foo44!(typeof(x)) f;
704 showf(typeid(f).toString());
705 assert(is(typeof(x) == const(int)));
706 assert(is(f == const(int)));
707 }
708
709 {
710 immutable int x;
711 alias Foo44!(typeof(x)) f;
712 showf(typeid(f).toString());
713 assert(is(typeof(x) == immutable(int)));
714 assert(is(f == immutable(int)));
715 }
716 }
717
718 /************************************/
719
720 template Foo45(T:const(T))
721 {
722 alias T Foo45;
723 }
724
test45()725 void test45()
726 {
727 {
728 int x;
729 alias Foo45!(typeof(x)) f;
730 showf(typeid(f).toString());
731 assert(is(typeof(x) == int));
732 assert(is(f == int));
733 }
734
735 {
736 const int x;
737 alias Foo45!(typeof(x)) f;
738 showf(typeid(f).toString());
739 assert(is(typeof(x) == const(int)));
740 assert(is(f == int));
741 }
742
743 {
744 immutable int x;
745 alias Foo45!(typeof(x)) f;
746 showf(typeid(f).toString());
747 assert(is(typeof(x) == immutable(int)));
748 assert(is(f == int));
749 }
750 }
751
752 /************************************/
753
754 template Foo46(T:immutable(T))
755 {
756 alias T Foo46;
757 }
758
test46()759 void test46()
760 {
761 {
762 immutable int x;
763 alias Foo46!(typeof(x)) f;
764 showf(typeid(f).toString());
765 assert(is(typeof(x) == immutable(int)));
766 assert(is(f == int));
767 }
768 }
769
770 /************************************/
771
772 template Foo47(T:T) { const int Foo47 = 2; }
773 template Foo47(T:const(T)) { const int Foo47 = 3; }
774 template Foo47(T:immutable(T)) { const int Foo47 = 4; }
775
test47()776 void test47()
777 {
778 int x2;
779 const int x3;
780 immutable int x4;
781
782 printf("%d\n", Foo47!(typeof(x2)));
783 printf("%d\n", Foo47!(typeof(x3)));
784 printf("%d\n", Foo47!(typeof(x4)));
785
786 assert(Foo47!(typeof(x2)) == 2);
787 assert(Foo47!(typeof(x3)) == 3);
788 assert(Foo47!(typeof(x4)) == 4);
789 }
790
791 /************************************/
792
foo48(T)793 int foo48(T)(const(T) t) { return 3; }
794
test48()795 void test48()
796 {
797 const int x = 4;
798 assert(foo48(x) == 3);
799 }
800
801 /************************************/
802
foo49(T)803 void foo49(T)(T[] t)
804 {
805 showf(typeid(typeof(t)).toString());
806 assert(is(T == immutable(char)));
807 }
808
bar49(T)809 void bar49(T)(const T t)
810 {
811 showf(typeid(T).toString());
812 assert(is(T == const(int)) || is(T == immutable(int)) || is(T == int));
813 }
814
test49()815 void test49()
816 {
817 string s;
818 foo49(s);
819 foo49("hello");
820
821 const int c = 1;
822 bar49(c);
823
824 immutable int i = 1;
825 bar49(i);
826
827 bar49(1);
828 }
829
830 /************************************/
831
foo50(T)832 void foo50(T)(T t)
833 {
834 showf(typeid(typeof(t)).toString());
835 assert(is(T == C));
836 }
837
baz50(T)838 void baz50(T)(T t)
839 {
840 showf(typeid(typeof(t)).toString());
841 assert(is(T == const(C)));
842 }
843
bar50(T)844 void bar50(T)(const T t)
845 {
846 showf(typeid(T).toString());
847 showf(typeid(typeof(t)).toString());
848 assert(is(T == C));
849 assert(is(typeof(t) == const(C)));
850 }
851
abc50(T)852 void abc50(T)(const T t)
853 {
854 showf(typeid(T).toString());
855 showf(typeid(typeof(t)).toString());
856 assert(is(T == C));
857 assert(is(typeof(t) == const(C)));
858 }
859
test50()860 void test50()
861 {
862 C c = new C;
863 const(C) d = new C;
864
865 foo50(c);
866 baz50(d);
867
868 bar50(c);
869 abc50(d);
870 }
871
872 /************************************/
873
test51()874 void test51()
875 {
876 const(C) d = new C;
877 //d = new C;
878 }
879
880 /************************************/
881
isStaticArray(T)882 template isStaticArray(T)
883 {
884 const bool isStaticArray = false;
885 }
886
887 template isStaticArray(T : T[N], size_t N)
888 {
889 const bool isStaticArray = true;
890 }
891
892 template isDynamicArray(T, U = void)
893 {
894 static const isDynamicArray = false;
895 }
896
897 template isDynamicArray(T : U[], U)
898 {
899 static const isDynamicArray = !isStaticArray!(T);
900 }
901
test52()902 void test52()
903 {
904 immutable(char[5])[int] aa = ([3:"hello", 4:"betty"]);
905
906 showf(typeid(typeof(aa.values)).toString());
907 static assert(isDynamicArray!(typeof(aa.values)));
908 }
909
910 /************************************/
911
foo53(string n)912 void foo53(string n) { }
913
read53(in string name)914 void read53(in string name)
915 {
916 foo53(name);
917 }
918
test53()919 void test53()
920 {
921 read53("hello");
922 }
923
924 /************************************/
925
bar54(const (wchar)[]s)926 void bar54(const(wchar)[] s) { }
927
test54()928 void test54()
929 {
930 const(wchar)[] fmt;
931 bar54("Orphan format specifier: %" ~ fmt);
932 }
933
934 /************************************/
935
936 struct S55
937 {
fooS55938 int foo() { return 1; }
fooS55939 int foo() const { return 2; }
fooS55940 int foo() immutable { return 3; }
941 }
942
test55()943 void test55()
944 {
945 S55 s1;
946 auto i = s1.foo();
947 assert(i == 1);
948
949 const S55 s2;
950 i = s2.foo();
951 assert(i == 2);
952
953 immutable S55 s3;
954 i = s3.foo();
955 assert(i == 3);
956 }
957
958 /************************************/
959
960 const struct S56 { int a; }
961
test56()962 void test56()
963 {
964 S56 s;
965 S56 t;
966 printf("S56.sizeof = %d\n", S56.sizeof);
967 //t = s;
968 }
969
970 /************************************/
971
972 struct S57
973 {
fooS57974 const void foo(this T)(int i)
975 {
976 showf(typeid(T).toString());
977 if (i == 1)
978 assert(is(T == const));
979 if (i == 2)
980 assert(!is(T == const));
981 if (i == 3)
982 assert(is(T == immutable));
983 }
984 }
985
test57()986 void test57()
987 {
988 const(S57) s;
989 (&s).foo(1);
990 S57 s2;
991 s2.foo(2);
992 immutable(S57) s3;
993 s3.foo(3);
994 }
995
996 /************************************/
997
998 class C58
999 {
1000 const(C58) c;
1001 const C58 y;
1002
this()1003 this()
1004 {
1005 y = null;
1006 c = null;
1007 }
1008
foo()1009 const void foo()
1010 {
1011 //c = null; // should fail
1012 }
1013
bar()1014 void bar()
1015 {
1016 //c = null;
1017 }
1018 }
1019
test58()1020 void test58()
1021 {
1022 }
1023
1024 /************************************/
1025
1026 class A59
1027 {
1028 int[] a;
this()1029 this() { a.length = 1; }
1030
ptr()1031 int* ptr() { return a.ptr; }
ptr()1032 const const(int)* ptr() { return a.ptr; }
immutable(int)1033 immutable immutable(int)* ptr() { return a.ptr; }
1034 }
1035
test59()1036 void test59()
1037 {
1038 auto a = new A59;
1039 const b = cast(const)new A59;
1040 immutable c = cast(immutable)new A59;
1041 }
1042
1043 /************************************/
1044
foo60(int i)1045 int foo60(int i) { return 1; }
foo60(const int i)1046 int foo60(const int i) { return 2; }
foo60(immutable int i)1047 int foo60(immutable int i) { return 3; }
1048
test60()1049 void test60()
1050 {
1051 int i;
1052 const int j;
1053 immutable int k;
1054
1055 assert(foo60(i) == 1);
1056 assert(foo60(j) == 2);
1057 assert(foo60(k) == 3);
1058 }
1059
1060 /************************************/
1061
foo61(T)1062 void foo61(T)(T arg)
1063 {
1064 alias const(T) CT;
1065 assert(is(const(int) == CT));
1066 //writeln(typeid(const(T)));
1067 //writeln(typeid(CT));
1068 }
1069
test61()1070 void test61()
1071 {
1072 int x = 42;
1073 foo61(x);
1074 }
1075
1076 /************************************/
1077
Foo62(T)1078 class Foo62(T) { }
1079
test62()1080 void test62()
1081 {
1082 const(Foo62!(int)) f = new Foo62!(int);
1083 assert(is(typeof(f) == const(Foo62!(int))));
1084 }
1085
1086 /************************************/
1087
1088 struct S63
1089 {
1090 int x;
1091 }
1092
foo63(const ref S63 scheme)1093 void foo63(const ref S63 scheme)
1094 {
1095 //scheme.x = 3;
1096 }
1097
test63()1098 void test63()
1099 {
1100 S63 scheme;
1101 foo63(scheme);
1102 }
1103
1104 /************************************/
1105
1106 struct S64
1107 {
1108 int a;
1109 long b;
1110 }
1111
test64()1112 void test64()
1113 {
1114 S64 s1 = S64(2,3);
1115 const s2 = S64(2,3);
1116 immutable S64 s3 = S64(2,3);
1117
1118 s1 = s1;
1119 s1 = s2;
1120 s1 = s3;
1121 }
1122
1123 /************************************/
1124
1125 struct S65
1126 {
1127 int a;
1128 long b;
1129 char *p;
1130 }
1131
test65()1132 void test65()
1133 { char c;
1134 S65 s1 = S65(2,3);
1135 const s2 = S65(2,3);
1136 immutable S65 s3 = S65(2,3);
1137
1138 S65 t1 = S65(2,3,null);
1139 const t2 = S65(2,3,null);
1140 immutable S65 t3 = S65(2,3,null);
1141 }
1142
1143 /************************************/
1144
1145 struct S66
1146 {
1147 int a;
1148 long b;
1149 }
1150
test66()1151 void test66()
1152 { char c;
1153 S66 s1 = S66(2,3);
1154 const s2 = S66(2,3);
1155 immutable S66 s3 = S66(2,3);
1156
1157 S66 t1 = s1;
1158 S66 t2 = s2;
1159 S66 t3 = s3;
1160
1161 const(S66) u1 = s1;
1162 const(S66) u2 = s2;
1163 const(S66) u3 = s3;
1164
1165 immutable(S66) v1 = s1;
1166 immutable(S66) v2 = s2;
1167 immutable(S66) v3 = s3;
1168 }
1169
1170 /************************************/
1171
1172 struct Foo68
1173 {
1174 int z;
1175 immutable int x;
1176 int y;
1177 }
1178
test68()1179 void test68()
1180 {
1181 Foo68 bar;
1182 bar.y = 2;
1183 }
1184
1185 /************************************/
1186
1187 class C69 {}
1188 struct S69 {}
1189
test69()1190 void test69()
1191 {
1192 immutable(S69)* si;
1193 S69* sm;
1194 bool a = si is sm;
1195
1196 immutable(C69) ci;
1197 const(C69) cm;
1198 bool b = ci is cm;
1199 }
1200
1201 /************************************/
1202
1203 struct S70
1204 {
1205 int i;
1206 }
1207
test70()1208 void test70()
1209 {
1210 S70 s;
1211 const(S70) cs = s;
1212 S70 s1 = cs;
1213 S70 s2 = cast(S70)cs;
1214 }
1215
1216 /************************************/
1217
test72()1218 void test72()
1219 {
1220 int a;
1221 const int b;
1222 enum { int c = 0 }
1223 immutable int d = 0;
1224
1225 assert(__traits(isSame, a, a));
1226 assert(__traits(isSame, b, b));
1227 assert(__traits(isSame, c, c));
1228 assert(__traits(isSame, d, d));
1229 }
1230
1231 /************************************/
1232
a73(const int[]data...)1233 void a73(const int [] data...)
1234 {
1235 a73(1);
1236 }
1237
test73()1238 void test73()
1239 {
1240 }
1241
1242 /************************************/
1243
1244 struct S74 { int x; }
1245
1246 const S74 s_const = {0};
1247
1248 S74 s_mutable = s_const;
1249
test74()1250 void test74()
1251 {
1252 }
1253
1254 /************************************/
1255
1256 struct A75 { int x; }
1257 struct B75 { A75 s1; }
1258
1259 const A75 s1_const = {0};
1260 const B75 s2_const = {s1_const};
1261
test75()1262 void test75()
1263 {
1264 }
1265
1266 /************************************/
1267
test76()1268 void test76()
1269 {
1270 int[int] array;
1271 const(int[int]) a = array;
1272 }
1273
1274 /************************************/
1275
test77()1276 void test77()
1277 {
1278 int[][] intArrayArray;
1279 int[][][] intArrayArrayArray;
1280
1281 // const(int)[][] f1 = intArrayArray;
1282 const(int[])[] f2 = intArrayArray;
1283
1284 // const(int)[][][] g1 = intArrayArrayArray;
1285 // const(int[])[][] g2 = intArrayArrayArray;
1286 const(int[][])[] g3 = intArrayArrayArray;
1287 }
1288
1289 /************************************/
1290
foo78(T)1291 void foo78(T)(const(T)[] arg1, const(T)[] arg2) { }
1292
test78()1293 void test78()
1294 {
1295 foo78("hello", "world".dup);
1296 foo78("hello", "world");
1297 foo78("hello".dup, "world".dup);
1298 foo78(cast(const)"hello", cast(const)"world");
1299 }
1300
1301 /************************************/
1302
1303 const bool[string] stopWords79;
1304
this()1305 static this()
1306 {
1307 stopWords79 = [ "a"[]:1 ];
1308 }
1309
test79()1310 void test79()
1311 {
1312 "abc" in stopWords79;
1313 }
1314
1315 /************************************/
1316
inout(int)1317 void test80(inout(int) _ = 0)
1318 {
1319 char x;
1320 inout(char) y = x;
1321
1322 const(char)[] c;
1323 immutable(char)[] i;
1324 shared(char)[] s;
1325 const(shared(char))[] sc;
1326 inout(char)[] w;
1327 inout(shared(char))[] sw;
1328
1329 c = c;
1330 c = i;
1331 static assert(!__traits(compiles, c = s));
1332 static assert(!__traits(compiles, c = sc));
1333 c = w;
1334 static assert(!__traits(compiles, c = sw));
1335
1336 static assert(!__traits(compiles, i = c));
1337 i = i;
1338 static assert(!__traits(compiles, i = s));
1339 static assert(!__traits(compiles, i = sc));
1340 static assert(!__traits(compiles, i = w));
1341 static assert(!__traits(compiles, i = sw));
1342
1343 static assert(!__traits(compiles, s = c));
1344 static assert(!__traits(compiles, s = i));
1345 s = s;
1346 static assert(!__traits(compiles, s = sc));
1347 static assert(!__traits(compiles, s = w));
1348 static assert(!__traits(compiles, s = sw));
1349
1350 static assert(!__traits(compiles, sc = c));
1351 sc = i;
1352 sc = s;
1353 sc = sc;
1354 static assert(!__traits(compiles, sc = w));
1355 sc = sw;
1356
1357 static assert(!__traits(compiles, w = c));
1358 static assert(!__traits(compiles, w = i));
1359 static assert(!__traits(compiles, w = s));
1360 static assert(!__traits(compiles, w = sc));
1361 w = w;
1362 static assert(!__traits(compiles, w = sw));
1363
1364 static assert(!__traits(compiles, sw = c));
1365 static assert(!__traits(compiles, sw = i));
1366 static assert(!__traits(compiles, sw = s));
1367 static assert(!__traits(compiles, sw = sc));
1368 static assert(!__traits(compiles, sw = w));
1369 sw = sw;
1370 }
1371
1372 /************************************/
1373
inout(int)1374 void test81(inout(int) _ = 0)
1375 {
1376 const(char)* c;
1377 immutable(char)* i;
1378 shared(char)* s;
1379 const(shared(char))* sc;
1380 inout(char)* w;
1381
1382 c = c;
1383 c = i;
1384 static assert(!__traits(compiles, c = s));
1385 static assert(!__traits(compiles, c = sc));
1386 c = w;
1387
1388 static assert(!__traits(compiles, i = c));
1389 i = i;
1390 static assert(!__traits(compiles, i = s));
1391 static assert(!__traits(compiles, i = sc));
1392 static assert(!__traits(compiles, i = w));
1393
1394 static assert(!__traits(compiles, s = c));
1395 static assert(!__traits(compiles, s = i));
1396 s = s;
1397 static assert(!__traits(compiles, s = sc));
1398 static assert(!__traits(compiles, s = w));
1399
1400 static assert(!__traits(compiles, sc = c));
1401 sc = i;
1402 sc = s;
1403 sc = sc;
1404 static assert(!__traits(compiles, sc = w));
1405
1406 static assert(!__traits(compiles, w = c));
1407 static assert(!__traits(compiles, w = i));
1408 static assert(!__traits(compiles, w = s));
1409 static assert(!__traits(compiles, w = sc));
1410 w = w;
1411 }
1412
1413 /************************************/
1414
1415
inout(int)1416 void test82(inout(int) _ = 0)
1417 {
1418 const(immutable(char)*) c;
1419 pragma(msg, typeof(c));
1420 static assert(typeof(c).stringof == "const(immutable(char)*)");
1421
1422 inout(immutable(char)*) d;
1423 pragma(msg, typeof(d));
1424 static assert(typeof(d).stringof == "inout(immutable(char)*)");
1425
1426 inout(const(char)*) e;
1427
1428 pragma(msg, typeof(e));
1429 static assert(is(typeof(e) == inout(const(char)*)));
1430 static assert(typeof(e).stringof == "inout(const(char)*)");
1431
1432 pragma(msg, typeof(*e));
1433 static assert(is(typeof(*e) == inout(const(char))));
1434 static assert(typeof(*e).stringof == "inout(const(char))");
1435
1436 inout const(char)* f;
1437 static assert(is(typeof(e) == typeof(f)));
1438
1439 inout(shared(char)) g;
1440 pragma(msg, typeof(g));
1441 static assert(typeof(g).stringof == "shared(inout(char))");
1442
1443 shared(inout(char)) h;
1444 pragma(msg, typeof(h));
1445 static assert(typeof(h).stringof == "shared(inout(char))");
1446
1447 inout(immutable(char)) i;
1448 pragma(msg, typeof(i));
1449 static assert(typeof(i).stringof == "immutable(char)");
1450
1451 immutable(inout(char)) j;
1452 pragma(msg, typeof(j));
1453 static assert(typeof(j).stringof == "immutable(char)");
1454
1455 inout(const(char)) k;
1456 pragma(msg, typeof(k));
1457 static assert(typeof(k).stringof == "inout(const(char))");
1458
1459 const(inout(char)) l;
1460 pragma(msg, typeof(l));
1461 static assert(typeof(l).stringof == "inout(const(char))");
1462
1463 shared(const(char)) m;
1464 pragma(msg, typeof(m));
1465 static assert(typeof(m).stringof == "shared(const(char))");
1466
1467 const(shared(char)) n;
1468 pragma(msg, typeof(n));
1469 static assert(typeof(n).stringof == "shared(const(char))");
1470
1471 inout(char*****) o;
1472 pragma(msg, typeof(o));
1473 static assert(typeof(o).stringof == "inout(char*****)");
1474 pragma(msg, typeof(cast()o));
1475 static assert(typeof(cast()o).stringof == "inout(char****)*");
1476
1477 const(char*****) p;
1478 pragma(msg, typeof(p));
1479 static assert(typeof(p).stringof == "const(char*****)");
1480 pragma(msg, typeof(cast()p));
1481 static assert(typeof(cast()p).stringof == "const(char****)*");
1482
1483 immutable(char*****) q;
1484 pragma(msg, typeof(q));
1485 static assert(typeof(q).stringof == "immutable(char*****)");
1486 pragma(msg, typeof(cast()q));
1487 static assert(typeof(cast()q).stringof == "immutable(char****)*");
1488
1489 shared(char*****) r;
1490 pragma(msg, typeof(r));
1491 static assert(typeof(r).stringof == "shared(char*****)");
1492 pragma(msg, typeof(cast()r));
1493 static assert(typeof(cast()r).stringof == "shared(char****)*");
1494 pragma(msg, typeof(cast(const)r));
1495 static assert(typeof(cast(const)r).stringof == "const(shared(char****)*)");
1496 pragma(msg, typeof(cast(const shared)r));
1497 static assert(typeof(cast(const shared)r).stringof == "shared(const(char*****))");
1498 pragma(msg, typeof(cast(shared)r));
1499 static assert(typeof(cast(shared)r).stringof == "shared(char*****)");
1500 pragma(msg, typeof(cast(immutable)r));
1501 static assert(typeof(cast(immutable)r).stringof == "immutable(char*****)");
1502 pragma(msg, typeof(cast(inout)r));
1503 static assert(typeof(cast(inout)r).stringof == "inout(shared(char****)*)");
1504
1505 inout(shared(char**)***) s;
1506 pragma(msg, typeof(s));
1507 static assert(typeof(s).stringof == "inout(shared(char**)***)");
1508 pragma(msg, typeof(***s));
1509 static assert(typeof(***s).stringof == "shared(inout(char**))");
1510 }
1511
1512 /************************************/
1513
inout(int)1514 void test83(inout(int) _ = 0)
1515 {
1516 static assert( __traits(compiles, typeid(int* function(inout int))));
1517 static assert( __traits(compiles, typeid(int* delegate(inout int))));
1518 static assert(!__traits(compiles, typeid(inout(int*) function(int))));
1519 static assert(!__traits(compiles, typeid(inout(int*) delegate(int))));
1520 static assert(!__traits(compiles, typeid(inout(int*) function())));
1521 static assert(!__traits(compiles, typeid(inout(int*) delegate())));
1522 inout(int*) function(inout(int)) fp;
1523 inout(int*) delegate(inout(int)) dg;
1524 }
1525
1526 /************************************/
1527
foo84(inout char[]s)1528 inout(char[]) foo84(inout char[] s) { return s; }
1529
test84()1530 void test84()
1531 {
1532 char[] m;
1533 const(char)[] c;
1534 string s;
1535 auto r = foo84(s);
1536 pragma(msg, typeof(r).stringof);
1537 static assert(typeof(r).stringof == "immutable(string)");
1538
1539 pragma(msg, typeof(foo84(c)).stringof);
1540 static assert(typeof(foo84(c)).stringof == "const(char[])");
1541
1542 pragma(msg, typeof(foo84(m)).stringof);
1543 static assert(typeof(foo84(m)).stringof == "char[]");
1544 }
1545
1546 /************************************/
1547
1548 class foo85 { }
1549
1550 alias shared foo85 Y85;
1551
test85()1552 void test85()
1553 {
1554 pragma(msg, Y85);
1555 shared(foo85) x = new Y85;
1556 }
1557
1558 /************************************/
1559
1560 struct foo87
1561 {
barfoo871562 int bar(T)(T t){ return 1; }
barfoo871563 int bar(T)(T t) shared { return 2; }
1564 }
1565
test87()1566 void test87()
1567 {
1568 foo87 x;
1569 auto i = x.bar(1);
1570 assert(i == 1);
1571 shared foo87 y;
1572 i = y.bar(1);
1573 assert(i == 2);
1574 }
1575
1576 /************************************/
1577 // 2751
1578
1579
test88(immutable (int[3])a)1580 void test88(immutable(int[3]) a)
1581 {
1582 const(char)[26] abc1 = "abcdefghijklmnopqrstuvwxyz";
1583 const(char[26]) abc2 = "abcdefghijklmnopqrstuvwxyz";
1584 immutable(const(char)[26]) abc3 = "abcdefghijklmnopqrstuvwxyz";
1585 const(immutable(char)[26]) abc4 = "abcdefghijklmnopqrstuvwxyz";
1586
1587 auto abc5 = cast()"abcdefghijklmnopqrstuvwxyz";
1588
1589 pragma(msg, typeof(abc1).stringof);
1590 pragma(msg, typeof(abc2).stringof);
1591 pragma(msg, typeof(abc3).stringof);
1592 pragma(msg, typeof(abc4).stringof);
1593 pragma(msg, typeof(abc5).stringof);
1594
1595 static assert(is(typeof(abc1) == typeof(abc2)));
1596 static assert(is(typeof(abc1) == const(char[26])));
1597 static assert(is(typeof(abc3) == typeof(abc4)));
1598 static assert(is(typeof(abc3) == immutable(char[26])));
1599
1600 auto b = cast()a;
1601 pragma(msg, typeof(b).stringof);
1602 static assert(is(typeof(b) == int[3]));
1603 }
1604
1605 /************************************/
1606 // 3748
1607
1608 // version = error8;
1609 // version = error11;
1610
1611 class C3748
1612 {
1613 private int _x;
this(int x)1614 this(int x) { this._x = x; }
inout(int)1615 @property inout(int)* xptr() inout { return &_x; }
x(int newval)1616 @property void x(int newval) { _x = newval; }
1617 }
1618
1619 struct S3748
1620 {
1621 int x;
1622 immutable int y = 5;
1623 const int z = 6;
1624 C3748 c;
1625
inoutS37481626 inout(int)* getX() inout
1627 {
1628 static assert(!__traits(compiles, {
1629 x = 4;
1630 }));
1631 return &x;
1632 }
inoutS37481633 inout(int)* getCX(C3748 otherc) inout
1634 {
1635 inout(C3748) c2 = c; // typeof(c) == inout(C3748)
1636 static assert(!__traits(compiles, {
1637 inout(C3748) err2 = new C3748(1);
1638 }));
1639 static assert(!__traits(compiles, {
1640 inout(C3748) err3 = otherc;
1641 }));
1642
1643 auto v1 = getLowestXptr(c, otherc);
1644 static assert(is(typeof(v1) == const(int)*));
1645 auto v2 = getLowestXptr(c, c);
1646 static assert(is(typeof(v2) == inout(int)*));
1647
1648 alias typeof(return) R;
1649 static assert(!__traits(compiles, {
1650 c.x = 4;
1651 }));
1652 static assert(!__traits(compiles, {
1653 R r = otherc.xptr;
1654 }));
1655 static assert(!__traits(compiles, {
1656 R r = &y;
1657 }));
1658 static assert(!__traits(compiles, {
1659 R r = &z;
1660 }));
1661
1662 return c2.xptr;
1663 }
1664
1665 version(error8)
1666 inout(int) err8; // see fail_compilation/failinout3748a.d
1667 }
1668
inout(int)1669 inout(int)* getLowestXptr(inout(C3748) c1, inout(C3748) c2)
1670 {
1671 inout(int)* x1 = c1.xptr;
1672 inout(int)* x2 = c2.xptr;
1673 if(*x1 <= *x2)
1674 return x1;
1675 return x2;
1676 }
1677
inout(int)1678 ref inout(int) getXRef(inout(C3748) c1, inout(C3748) c2)
1679 {
1680 return *getLowestXptr(c1, c2);
1681 }
1682
test3748()1683 void test3748()
1684 {
1685 S3748 s;
1686 s.c = new C3748(1);
1687 const(S3748)* sp = &s;
1688 auto s2 = new S3748;
1689 s2.x = 3;
1690 s2.c = new C3748(2);
1691 auto s3 = cast(immutable(S3748)*) s2;
1692
1693 auto v1 = s.getX;
1694 static assert(is(typeof(v1) == int*));
1695 auto v2 = sp.getX;
1696 static assert(is(typeof(v2) == const(int)*));
1697 auto v3 = s3.getX;
1698 static assert(is(typeof(v3) == immutable(int)*));
1699
1700 static assert(!__traits(compiles, {
1701 int *err9 = sp.getX;
1702 }));
1703 static assert(!__traits(compiles, {
1704 int *err10 = s3.getX;
1705 }));
1706 version(error11)
1707 inout(int)* err11; // see fail_compilation/failinout3748b.d
1708
1709 auto v4 = getLowestXptr(s.c, s3.c);
1710 static assert(is(typeof(v4) == const(int)*));
1711 auto v5 = getLowestXptr(s.c, s.c);
1712 static assert(is(typeof(v5) == int*));
1713 auto v6 = getLowestXptr(s3.c, s3.c);
1714 static assert(is(typeof(v6) == immutable(int)*));
1715
1716 getXRef(s.c, s.c) = 3;
1717 }
1718
1719 /************************************/
1720
1721 void test3748a(inout int = 1)
1722 {
1723 int[] ma;
1724 inout(int[]) wa;
1725 const(int[]) ca;
1726 immutable(int[]) ia;
1727 shared(int[]) sa;
1728 shared(inout(int[])) swa;
1729 shared(const(int[])) sca;
1730
foo1(E)1731 static foo1(E)(inout(E[]) a) { return E.init; }
1732 static assert( is( typeof(foo1( ma)) == int));
1733 static assert( is( typeof(foo1( wa)) == int));
1734 static assert( is( typeof(foo1( ca)) == int));
1735 static assert( is( typeof(foo1( ia)) == int));
1736 static assert( is( typeof(foo1( sa)) == shared int));
1737 static assert( is( typeof(foo1(swa)) == shared int));
1738 static assert( is( typeof(foo1(sca)) == shared int));
1739
foo2(E)1740 static foo2(E)(shared inout(E[]) a) { return E.init; }
1741 static assert(!is( typeof(foo2( ma)) ));
1742 static assert(!is( typeof(foo2( wa)) ));
1743 static assert(!is( typeof(foo2( ca)) ));
1744 static assert( is( typeof(foo2( ia)) == int));
1745 static assert( is( typeof(foo2( sa)) == int));
1746 static assert( is( typeof(foo2(swa)) == int));
1747 static assert( is( typeof(foo2(sca)) == int));
1748 }
1749
1750 void test3748b(inout int = 1)
1751 {
1752 // Top of the parameter type is non-ref & qualified
1753 static inout(int[]) foo1( inout(int[]) a);
1754 static shared(inout(int[])) bar1(shared(inout(int[])) a);
1755
1756 // Top of the parameter type is non-ref & un-qualified
1757 static inout(int) [] foo2( inout(int) [] a);
1758 static shared(inout(int))[] bar2(shared(inout(int))[] a);
1759
1760 // Top of the argument type is qualified
1761 int[] ma1;
1762 inout(int[]) wa1;
1763 const(int[]) ca1;
1764 shared(int[]) sa1;
1765 shared(inout(int[])) swa1;
1766 shared(const(int[])) sca1;
1767 immutable(int[]) ia1;
1768
1769 // Top of the argument type is un-qualified
1770 int [] ma2;
1771 inout(int) [] wa2;
1772 const(int) [] ca2;
1773 shared(int) [] sa2;
1774 shared(inout(int))[] swa2;
1775 shared(const(int))[] sca2;
1776 immutable(int) [] ia2;
1777
1778 // --> non-ref qualified param VS qualified arg
1779 static assert( is( typeof(foo1( ma1)) == typeof( ma1) ));
1780 static assert( is( typeof(foo1( wa1)) == typeof( wa1) ));
1781 static assert( is( typeof(foo1( ca1)) == typeof( ca1) ));
1782 static assert( is( typeof(bar1( sa1)) == typeof( sa1) ));
1783 static assert( is( typeof(bar1(swa1)) == typeof(swa1) ));
1784 static assert( is( typeof(bar1(sca1)) == typeof(sca1) ));
1785 static assert( is( typeof(foo1( ia1)) == typeof( ia1) ));
1786
1787 // --> non-ref un-qualified param VS qualified arg
1788 static assert( is( typeof(foo2( ma1)) == typeof( ma2) ));
1789 static assert( is( typeof(foo2( wa1)) == typeof( wa2) ));
1790 static assert( is( typeof(foo2( ca1)) == typeof( ca2) ));
1791 static assert( is( typeof(bar2( sa1)) == typeof( sa2) ));
1792 static assert( is( typeof(bar2(swa1)) == typeof(swa2) ));
1793 static assert( is( typeof(bar2(sca1)) == typeof(sca2) ));
1794 static assert( is( typeof(foo2( ia1)) == typeof( ia2) ));
1795
1796 // --> non-ref qualified param VS un-qualified arg
1797 static assert( is( typeof(foo1( ma2)) == typeof( ma1) ));
1798 static assert( is( typeof(foo1( wa2)) ));
1799 static assert( is( typeof(foo1( ca2)) ));
1800 static assert( is( typeof(bar1( sa2)) == typeof( sa1) ));
1801 static assert( is( typeof(bar1(swa2)) ));
1802 static assert( is( typeof(bar1(sca2)) ));
1803 static assert( is( typeof(foo1( ia2)) ));
1804
1805 // --> non-ref un-qualified param VS un-qualified arg
1806 static assert( is( typeof(foo2( ma2)) == typeof( ma2) ));
1807 static assert( is( typeof(foo2( wa2)) == typeof( wa2) ));
1808 static assert( is( typeof(foo2( ca2)) == typeof( ca2) ));
1809 static assert( is( typeof(bar2( sa2)) == typeof( sa2) ));
1810 static assert( is( typeof(bar2(swa2)) == typeof(swa2) ));
1811 static assert( is( typeof(bar2(sca2)) == typeof(sca2) ));
1812 static assert( is( typeof(foo2( ia2)) == typeof( ia2) ));
1813 }
1814
1815 void test3748c(inout int = 1)
1816 {
1817 // Top of the parameter type is ref & qualified
1818 static inout(int[]) foo1(ref inout(int[]) a);
1819 static shared(inout(int[])) bar1(ref shared(inout(int[])) a);
1820
1821 // Top of the parameter type is ref & un-qualified
1822 static inout(int) [] foo2(ref inout(int) [] a);
1823 static shared(inout(int))[] bar2(ref shared(inout(int))[] a);
1824
1825 // Top of the argument type is qualified
1826 int[] ma1;
1827 inout(int[]) wa1;
1828 const(int[]) ca1;
1829 shared(int[]) sa1;
1830 shared(inout(int[])) swa1;
1831 shared(const(int[])) sca1;
1832 immutable(int[]) ia1;
1833
1834 // Top of the argument type is un-qualified
1835 int [] ma2;
1836 inout(int) [] wa2;
1837 const(int) [] ca2;
1838 shared(int) [] sa2;
1839 shared(inout(int))[] swa2;
1840 shared(const(int))[] sca2;
1841 immutable(int) [] ia2;
1842
1843 // --> ref qualified param VS qualified arg
1844 static assert( is( typeof(foo1( ma1)) == typeof( ma1) ));
1845 static assert( is( typeof(foo1( wa1)) == typeof( wa1) ));
1846 static assert( is( typeof(foo1( ca1)) == typeof( ca1) ));
1847 static assert( is( typeof(bar1( sa1)) == typeof( sa1) ));
1848 static assert( is( typeof(bar1(swa1)) == typeof(swa1) ));
1849 static assert( is( typeof(bar1(sca1)) == typeof(sca1) ));
1850 static assert( is( typeof(foo1( ia1)) == typeof( ia1) ));
1851
1852 // --> ref un-qualified param VS qualified arg
1853 static assert( is( typeof(foo2( ma1)) == typeof( ma2) ));
1854 static assert(!is( typeof(foo2( wa1)) ));
1855 static assert(!is( typeof(foo2( ca1)) ));
1856 static assert(!is( typeof(bar2( sa1)) ));
1857 static assert(!is( typeof(bar2(swa1)) ));
1858 static assert(!is( typeof(bar2(sca1)) ));
1859 static assert(!is( typeof(foo2( ia1)) ));
1860
1861 // --> ref qualified param VS un-qualified arg
1862 static assert( is( typeof(foo1( ma2)) == typeof( ma1) ));
1863 static assert(!is( typeof(foo1( wa2)) ));
1864 static assert(!is( typeof(foo1( ca2)) )); // why this is OK? --> [*]
1865 static assert(!is( typeof(bar1( sa2)) ));
1866 static assert(!is( typeof(bar1(swa2)) ));
1867 static assert(!is( typeof(bar1(sca2)) ));
1868 static assert(!is( typeof(foo1( ia2)) ));
1869
1870 // --> ref un-qualified param VS un-qualified arg
1871 static assert( is( typeof(foo2( ma2)) == typeof( ma2) ));
1872 static assert( is( typeof(foo2( wa2)) == typeof( wa2) ));
1873 static assert( is( typeof(foo2( ca2)) == typeof( ca2) ));
1874 static assert( is( typeof(bar2( sa2)) == typeof( sa2) ));
1875 static assert( is( typeof(bar2(swa2)) == typeof(swa2) ));
1876 static assert( is( typeof(bar2(sca2)) == typeof(sca2) ));
1877 static assert( is( typeof(foo2( ia2)) == typeof( ia2) ));
1878 }
1879
1880 /************************************/
1881 // 4968
1882
test4968()1883 void test4968()
1884 {
1885 inout(int) f1(inout(int) i) { return i; }
1886 int mi;
1887 const int ci;
1888 immutable int ii;
1889 static assert(is(typeof(f1(mi)) == int));
1890 static assert(is(typeof(f1(ci)) == const(int)));
1891 static assert(is(typeof(f1(ii)) == immutable(int)));
1892
1893 inout(int)* f2(inout(int)* p) { return p; }
1894 int* mp;
1895 const(int)* cp;
1896 immutable(int)* ip;
1897 static assert(is(typeof(f2(mp)) == int*));
1898 static assert(is(typeof(f2(cp)) == const(int)*));
1899 static assert(is(typeof(f2(ip)) == immutable(int)*));
1900
1901 inout(int)[] f3(inout(int)[] a) { return a; }
1902 int[] ma;
1903 const(int)[] ca;
1904 immutable(int)[] ia;
1905 static assert(is(typeof(f3(ma)) == int[]));
1906 static assert(is(typeof(f3(ca)) == const(int)[]));
1907 static assert(is(typeof(f3(ia)) == immutable(int)[]));
1908
1909 inout(int)[1] f4(inout(int)[1] sa) { return sa; }
1910 int[1] msa;
1911 const int[1] csa;
1912 immutable int[1] isa;
1913 static assert(is(typeof(f4(msa)) == int[1]));
1914 static assert(is(typeof(f4(csa)) == const(int)[1]));
1915 static assert(is(typeof(f4(isa)) == immutable(int)[1]));
1916
1917 inout(int)[string] f5(inout(int)[string] aa) { return aa; }
1918 int[string] maa;
1919 const(int)[string] caa;
1920 immutable(int)[string] iaa;
1921 static assert(is(typeof(f5(maa)) == int[string]));
1922 static assert(is(typeof(f5(caa)) == const(int)[string]));
1923 static assert(is(typeof(f5(iaa)) == immutable(int)[string]));
1924 }
1925
1926 /************************************/
1927 // 1961
1928
inout(char)1929 inout(char)[] strstr(inout(char)[] source, const(char)[] pattern)
1930 {
1931 /*
1932 * this would be an error, as const(char)[] is not implicitly castable to
1933 * inout(char)[]
1934 */
1935 // return pattern;
1936
1937 for(int i = 0; i + pattern.length <= source.length; i++)
1938 {
1939 inout(char)[] tmp = source[i..pattern.length]; // ok
1940 if (tmp == pattern) // ok, tmp implicitly casts to const(char)[]
1941 return source[i..$]; // implicitly casts back to call-site source
1942 }
1943 return source[$..$]; // to be consistent with strstr.
1944 }
1945
test1961a()1946 void test1961a()
1947 {
1948 auto a = "hello";
1949 a = strstr(a, "llo"); // cf (constancy factor) == immutable
1950 static assert(!__traits(compiles, { char[] b = strstr(a, "llo"); }));
1951 // error, cannot cast immutable to mutable
1952 char[] b = "hello".dup;
1953 b = strstr(b, "llo"); // cf == mutable (note that "llo" doesn't play a role
1954 // because that parameter is not inout)
1955 const(char)[] c = strstr(b, "llo");
1956 // cf = mutable, ok because mutable
1957 // implicitly casts to const
1958 c = strstr(a, "llo"); // cf = immutable, ok immutable casts to const
1959 }
1960
min(T)1961 inout(T) min(T)(inout(T) a, inout(T) b)
1962 {
1963 return a < b ? a : b;
1964 }
1965
test1961b()1966 void test1961b()
1967 {
1968 immutable(char)[] i = "hello";
1969 const(char)[] c = "there";
1970 char[] m = "Walter".dup;
1971
1972 static assert(!__traits(compiles, { i = min(i, c); }));
1973 // error, since i and c vary in constancy, the result
1974 // is const, and you cannot implicitly cast const to immutable.
1975
1976 c = min(i, c); // ok, cf == const, because not homogeneous
1977 c = min(m, c); // ok, cf == const
1978 c = min(m, i); // ok, cf == const
1979 i = min(i, "blah"); // ok, cf == immutable, homogeneous
1980 static assert(!__traits(compiles, { m = min(m, c); }));
1981 // error, cf == const because not homogeneous.
1982 static assert(!__traits(compiles, { m = min(m, "blah"); }));
1983 // error, cf == const
1984 m = min(m, "blah".dup); // ok
1985 }
1986
min2(int i,int j,T)1987 inout(T) min2(int i, int j, T)(inout(T) a, inout(T) b)
1988 {
1989 //pragma(msg, "(", i, ", ", j, ") = ", T);
1990 static assert(is(T == char[]));
1991 return a < b ? a : b;
1992 }
1993
seq(T...)1994 template seq(T...){ alias T seq; }
1995
test1961c()1996 void test1961c()
1997 {
1998 immutable(char[]) iia = "hello1";
1999 immutable(char)[] ima = "hello2";
2000 const(char[]) cca = "there1";
2001 const(char)[] cma = "there2";
2002 char[] mma = "Walter".dup;
2003
2004 foreach (i, x; seq!(iia, ima, cca, cma, mma))
2005 foreach (j, y; seq!(iia, ima, cca, cma, mma))
2006 {
2007 min2!(i, j)(x, y);
2008 //pragma(msg, "x: ",typeof(x), ", y: ",typeof(y), " -> ", typeof(min2(x, y)), " : ", __traits(compiles, min2(x, y)));
2009 }
2010 }
2011
2012 /************************************/
2013
function(inout (int))2014 inout(int) function(inout(int)) notinoutfun1() { return null; }
function(inout (int))2015 inout(int) function(inout(int))[] notinoutfun2() { return null; }
delegate(inout (int))2016 inout(int) delegate(inout(int)) notinoutfun3() { return null; }
delegate(inout (int))2017 inout(int) delegate(inout(int))[] notinoutfun4() { return null; }
notinoutfun1(inout (int)function (inout (int))fn)2018 void notinoutfun1(inout(int) function(inout(int)) fn) {}
notinoutfun2(inout (int)function (inout (int))[]fn)2019 void notinoutfun2(inout(int) function(inout(int))[] fn) {}
notinoutfun3(inout (int)delegate (inout (int))dg)2020 void notinoutfun3(inout(int) delegate(inout(int)) dg) {}
notinoutfun4(inout (int)delegate (inout (int))[]dg)2021 void notinoutfun4(inout(int) delegate(inout(int))[] dg) {}
2022
test88()2023 void test88()
2024 {
2025 inout(int) function(inout int) fp;
2026 inout(int) delegate(inout int) dg;
2027
2028 inout(int) function(inout int)* fp2p;
2029 inout(int) function(inout int)[] fp2a;
2030 inout(int) function(inout int)[3] fp2s;
2031
2032 inout(int) delegate(inout int)* dg3p;
2033 inout(int) delegate(inout int)[] dg3a;
2034 inout(int) delegate(inout int)[3] dg3s;
2035
2036 int delegate() inout* dg4p;
2037 int delegate() inout[] dg4a;
2038 int delegate() inout[3] dg4s;
2039
2040 static assert(!__traits(compiles, { inout(int)* p; }));
2041 static assert(!__traits(compiles, { inout(int delegate()) dg; }));
2042 }
2043
2044 /************************************/
2045 // 4251
2046
test4251a()2047 void test4251a()
2048 {
2049 alias int T;
2050
2051 static assert(!is( immutable(T)** : const(T)** )); // NG, tail difference
2052 static assert( is( immutable(T)** : const(T**) )); // OK, tail to const
2053
2054 static assert( is( T *** : T *** )); // OK, tail is same
2055 static assert(!is( T *** : const(T)*** ));
2056 static assert(!is( T *** : const(T*)** ));
2057 static assert( is( T *** : const(T**)* )); // OK, tail to const
2058 static assert( is( T *** : const(T***) )); // OK, tail to const
2059 static assert(!is( T *** : immutable(T)*** ));
2060 static assert(!is( T *** : immutable(T*)** ));
2061 static assert(!is( T *** : immutable(T**)* ));
2062 static assert(!is( T *** : immutable(T***) ));
2063
2064 static assert(!is( const(T)*** : T *** ));
2065 static assert( is( const(T)*** : const(T)*** )); // OK, tail is same
2066 static assert(!is( const(T)*** : const(T*)** ));
2067 static assert( is( const(T)*** : const(T**)* )); // OK, tail to const
2068 static assert( is( const(T)*** : const(T***) )); // OK, tail to const
2069 static assert(!is( const(T)*** : immutable(T)*** ));
2070 static assert(!is( const(T)*** : immutable(T*)** ));
2071 static assert(!is( const(T)*** : immutable(T**)* ));
2072 static assert(!is( const(T)*** : immutable(T***) ));
2073
2074 static assert(!is( const(T*)** : T *** ));
2075 static assert(!is( const(T*)** : const(T)*** ));
2076 static assert( is( const(T*)** : const(T*)** )); // OK, tail is same
2077 static assert( is( const(T*)** : const(T**)* )); // OK, tail to const
2078 static assert( is( const(T*)** : const(T***) )); // OK, tail to const
2079 static assert(!is( const(T*)** : immutable(T)*** ));
2080 static assert(!is( const(T*)** : immutable(T*)** ));
2081 static assert(!is( const(T*)** : immutable(T**)* ));
2082 static assert(!is( const(T*)** : immutable(T***) ));
2083
2084 static assert(!is( const(T**)* : T *** ));
2085 static assert(!is( const(T**)* : const(T)*** ));
2086 static assert(!is( const(T**)* : const(T*)** ));
2087 static assert( is( const(T**)* : const(T**)* )); // OK, tail is same
2088 static assert( is( const(T**)* : const(T***) )); // OK, tail is same
2089 static assert(!is( const(T**)* : immutable(T)*** ));
2090 static assert(!is( const(T**)* : immutable(T*)** ));
2091 static assert(!is( const(T**)* : immutable(T**)* ));
2092 static assert(!is( const(T**)* : immutable(T***) ));
2093
2094 static assert(!is( const(T***) : T *** ));
2095 static assert(!is( const(T***) : const(T)*** ));
2096 static assert(!is( const(T***) : const(T*)** ));
2097 static assert( is( const(T***) : const(T**)* )); // OK, tail is same
2098 static assert( is( const(T***) : const(T***) )); // OK, tail is same
2099 static assert(!is( const(T***) : T *** ));
2100 static assert(!is( const(T***) : immutable(T)*** ));
2101 static assert(!is( const(T***) : immutable(T*)** ));
2102 static assert(!is( const(T***) : immutable(T**)* ));
2103 static assert(!is( const(T***) : immutable(T***) ));
2104
2105 static assert(!is( immutable(T)*** : T *** ));
2106 static assert(!is( immutable(T)*** : const(T)*** ));
2107 static assert(!is( immutable(T)*** : const(T*)** ));
2108 static assert( is( immutable(T)*** : const(T**)* )); // OK, tail to const
2109 static assert( is( immutable(T)*** : const(T***) )); // OK, tail to const
2110 static assert( is( immutable(T)*** : immutable(T)*** )); // OK, tail is same
2111 static assert(!is( immutable(T)*** : immutable(T*)** ));
2112 static assert(!is( immutable(T)*** : immutable(T**)* ));
2113 static assert(!is( immutable(T)*** : immutable(T***) ));
2114
2115 static assert(!is( immutable(T*)** : T *** ));
2116 static assert(!is( immutable(T*)** : const(T)*** ));
2117 static assert(!is( immutable(T*)** : const(T*)** ));
2118 static assert( is( immutable(T*)** : const(T**)* )); // OK, tail to const
2119 static assert( is( immutable(T*)** : const(T***) )); // OK, tail to const
2120 static assert(!is( immutable(T*)** : immutable(T)*** ));
2121 static assert( is( immutable(T*)** : immutable(T*)** )); // OK, tail is same
2122 static assert(!is( immutable(T*)** : immutable(T**)* ));
2123 static assert(!is( immutable(T*)** : immutable(T***) ));
2124
2125 static assert(!is( immutable(T**)* : T *** ));
2126 static assert(!is( immutable(T**)* : const(T)*** ));
2127 static assert(!is( immutable(T**)* : const(T*)** ));
2128 static assert( is( immutable(T**)* : const(T**)* )); // OK, tail to const
2129 static assert( is( immutable(T**)* : const(T***) )); // OK, tail to const
2130 static assert(!is( immutable(T**)* : immutable(T)*** ));
2131 static assert(!is( immutable(T**)* : immutable(T*)** ));
2132 static assert( is( immutable(T**)* : immutable(T**)* )); // OK, tail is same
2133 static assert( is( immutable(T**)* : immutable(T***) )); // OK, tail is same
2134
2135 static assert(!is( immutable(T***) : T *** ));
2136 static assert(!is( immutable(T***) : const(T)*** ));
2137 static assert(!is( immutable(T***) : const(T*)** ));
2138 static assert( is( immutable(T***) : const(T**)* )); // OK, tail to const
2139 static assert( is( immutable(T***) : const(T***) )); // OK, tail to const
2140 static assert(!is( immutable(T***) : immutable(T)*** ));
2141 static assert(!is( immutable(T***) : immutable(T*)** ));
2142 static assert( is( immutable(T***) : immutable(T**)* )); // OK, tail is same
2143 static assert( is( immutable(T***) : immutable(T***) )); // OK, tail is same
2144
2145 static assert( is( immutable(int)** : const(immutable(int)*)* )); // OK, tail to const
2146
2147 // shared level should be same
2148 static assert(!is( shared(T)*** : const(T***) )); // NG, tail to const but shared level is different
2149 static assert( is( shared(T***) : shared(const(T***)) )); // OK, tail to const and shared level is same
2150
2151 // head qualifier difference is ignored
2152 static assert(is( shared(int)* : shared(int*) ));
2153 static assert(is( inout (int)* : inout (int*) ));
2154
2155 //
2156 static assert(!is( T** : T*** ));
2157 static assert(!is( T[]** : T*** ));
2158 }
2159
test4251b()2160 void test4251b()
2161 {
2162 class C {}
2163 class D : C {}
2164
2165 static assert(!is( C[]* : const(C)[]* ));
2166 static assert( is( C[]* : const(C[])* ));
2167
2168 // derived class to const(base class) in tail
2169 static assert( is( D[] : const(C)[] ));
2170 static assert( is( D[]* : const(C[])* ));
2171
2172 static assert( is( D* : const(C)* ));
2173 static assert( is( D** : const(C*)* ));
2174
2175 // derived class to const(base interface) in tail
2176 interface I {}
2177 class X : I {}
2178 static assert(!is( X[] : const(I)[] ));
2179
2180 // interface to const(base interface) in tail
2181 interface J {}
2182 interface K : I, J {}
2183 static assert( is( K[] : const(I)[] )); // OK, runtime offset is same
2184 static assert(!is( K[] : const(J)[] )); // NG, runtime offset is different
2185 }
2186
2187 /************************************/
2188 // 5473
2189
test5473()2190 void test5473()
2191 {
2192 class C
2193 {
2194 int b;
2195 void f(){}
2196 static int x;
2197 static void g(){};
2198 }
2199 struct S
2200 {
2201 int b;
2202 void f(){}
2203 static int x;
2204 static void g(){};
2205 }
2206
2207 void dummy();
2208 alias typeof(dummy) VoidFunc;
2209
2210 const C c = new C;
2211 const S s;
2212
2213 foreach (a; TypeTuple!(c, s))
2214 {
2215 alias typeof(a) A;
2216
2217 static assert(is(typeof(a.b) == const int)); // const(int)
2218 static assert(is(typeof(a.f) == VoidFunc));
2219 static assert(is(typeof(a.x) == int));
2220 static assert(is(typeof(a.g) == VoidFunc));
2221
2222 static assert(is(typeof((const A).b) == const int)); // int, should be const(int)
2223 static assert(is(typeof((const A).f) == VoidFunc));
2224 static assert(is(typeof((const A).x) == int));
2225 static assert(is(typeof((const A).g) == VoidFunc));
2226 }
2227 }
2228
2229 /************************************/
2230 // 5493
2231
test5493()2232 void test5493()
2233 {
2234 // non template function
2235 void pifun(immutable(char)[]* a) {}
2236 void rifun(ref immutable(char)[] a) {}
2237
2238 void pcfun(const(char)[]* a) {}
2239 void rcfun(ref const(char)[] a) {}
2240
2241 immutable char[] buf1 = "hello";
2242 static assert(!__traits(compiles, pifun(buf1)));
2243 static assert(!__traits(compiles, pcfun(buf1)));
2244 static assert(!__traits(compiles, rifun(buf1)));
2245 static assert(!__traits(compiles, rcfun(buf1)));
2246
2247 immutable char[5] buf2 = "hello";
2248 static assert(!__traits(compiles, pifun(buf2)));
2249 static assert(!__traits(compiles, pcfun(buf2)));
2250 static assert(!__traits(compiles, rifun(buf2)));
2251 static assert(!__traits(compiles, rcfun(buf2)));
2252
2253 const char[] buf3 = "hello";
2254 static assert(!__traits(compiles, pcfun(buf3)));
2255 static assert(!__traits(compiles, rcfun(buf3)));
2256
2257 const char[5] buf4 = "hello";
2258 static assert(!__traits(compiles, pcfun(buf4)));
2259 static assert(!__traits(compiles, rcfun(buf4)));
2260
2261 // template function
2262 void pmesswith(T)(const(T)[]* ts, const(T) t)
2263 {
2264 *ts ~= t;
2265 }
2266 void rmesswith(T)(ref const(T)[] ts, const(T) t)
2267 {
2268 ts ~= t;
2269 }
2270 class C
2271 {
2272 int x;
2273 this(int i) immutable { x = i; }
2274 }
2275 C[] cs;
2276 immutable C ci = new immutable(C)(6);
2277 assert (ci.x == 6);
2278 static assert(!__traits(compiles, pmesswith(&cs,ci)));
2279 static assert(!__traits(compiles, rmesswith(cs,ci)));
2280 //cs[$-1].x = 14;
2281 //assert (ci.x == 14); //whoops.
2282 }
2283
2284 /************************************/
2285 // 5493 + inout
2286
test5493inout()2287 void test5493inout()
2288 {
2289 int m;
2290 const(int) c;
2291 immutable(int) i;
2292
2293 inout(int) ptrfoo(inout(int)** a, inout(int)* b)
2294 {
2295 *a = b;
2296 return 0; // dummy
2297 }
2298 inout(int) reffoo(ref inout(int)* a, inout(int)* b)
2299 {
2300 a = b;
2301 return 0; // dummy
2302 }
2303
2304 // wild matching: inout == mutable
2305 int* pm;
2306 ptrfoo(&pm, &m); assert(pm == &m);
2307 static assert(!__traits(compiles, ptrfoo(&pm, &c)));
2308 static assert(!__traits(compiles, ptrfoo(&pm, &i)));
2309 reffoo( pm, &m); assert(pm == &m);
2310 static assert(!__traits(compiles, reffoo( pm, &c)));
2311 static assert(!__traits(compiles, reffoo( pm, &i)));
2312
2313 // wild matching: inout == const
2314 const(int)* pc;
2315 ptrfoo(&pc, &m); assert(pc == &m);
2316 ptrfoo(&pc, &c); assert(pc == &c);
2317 ptrfoo(&pc, &i); assert(pc == &i);
2318 reffoo( pc, &m); assert(pc == &m);
2319 reffoo( pc, &c); assert(pc == &c);
2320 reffoo( pc, &i); assert(pc == &i);
2321
2322 // wild matching: inout == immutable
2323 immutable(int)* pi;
2324 static assert(!__traits(compiles, ptrfoo(&pi, &m)));
2325 static assert(!__traits(compiles, ptrfoo(&pi, &c)));
2326 ptrfoo(&pi, &i); assert(pi == &i);
2327 static assert(!__traits(compiles, reffoo( pi, &m)));
2328 static assert(!__traits(compiles, reffoo( pi, &c)));
2329 reffoo( pi, &i); assert(pi == &i);
2330 }
2331
2332 /************************************/
2333 // 6782
2334
Tuple6782(T...)2335 struct Tuple6782(T...)
2336 {
2337 T field;
2338 alias field this;
2339 }
tuple6782(T...)2340 auto tuple6782(T...)(T field)
2341 {
2342 return Tuple6782!T(field);
2343 }
2344
2345 struct Range6782a
2346 {
2347 int *ptr;
inoutRange6782a2348 @property inout(int)* front() inout { return ptr; }
emptyRange6782a2349 @property bool empty() const { return ptr is null; }
popFrontRange6782a2350 void popFront() { ptr = null; }
2351 }
2352 struct Range6782b
2353 {
2354 Tuple6782!(int, int*) e;
front()2355 @property front() inout { return e; }
empty()2356 @property empty() const { return e[1] is null; }
popFront()2357 void popFront() { e[1] = null; }
2358 }
2359
test6782()2360 void test6782()
2361 {
2362 int x = 5;
2363 auto r1 = Range6782a(&x);
2364 foreach(p; r1) {}
2365
2366 auto r2 = Range6782b(tuple6782(1, &x));
2367 foreach(i, p; r2) {}
2368 }
2369
2370 /************************************/
2371 // 6864
2372
fn6864(const int n)2373 int fn6864( const int n) { return 1; }
fn6864(shared int n)2374 int fn6864(shared int n) { return 2; }
fw6864(inout int s)2375 inout(int) fw6864(inout int s) { return 1; }
fw6864(shared inout int s)2376 inout(int) fw6864(shared inout int s) { return 2; }
2377
test6864()2378 void test6864()
2379 {
2380 int n;
2381 assert(fn6864(n) == 1);
2382 assert(fw6864(n) == 1);
2383
2384 shared int sn;
2385 assert(fn6864(sn) == 2);
2386 assert(fw6864(sn) == 2);
2387 }
2388
2389 /************************************/
2390 // 6865
2391
foo6865(shared (inout (int))n)2392 shared(inout(int)) foo6865(shared(inout(int)) n){ return n; }
test6865()2393 void test6865()
2394 {
2395 shared(const(int)) n;
2396 static assert(is(typeof(foo6865(n)) == shared(const(int))));
2397 }
2398
2399 /************************************/
2400 // 6866
2401
2402 struct S6866
2403 {
2404 const(char)[] val;
2405 alias val this;
2406 }
inout(char)2407 inout(char)[] foo6866(inout(char)[] s) { return s; }
2408
test6866()2409 void test6866()
2410 {
2411 S6866 s;
2412 static assert(is(typeof(foo6866(s)) == const(char)[]));
2413 // Assertion failure: 'targ' on line 2029 in file 'mtype.c'
2414 }
2415
2416 /************************************/
2417 // 6867
2418
inout(char)2419 inout(char)[] test6867(inout(char)[] a)
2420 {
2421 foreach(dchar d; a) // No error if 'dchar' is removed
2422 {
2423 foreach(c; a) // line 5
2424 {
2425 }
2426 }
2427 return [];
2428 }
2429
2430 /************************************/
2431 // 6870
2432
test6870()2433 void test6870()
2434 {
2435 shared(int) x;
2436 static assert(is(typeof(x) == shared(int))); // pass
2437 const(typeof(x)) y;
2438 const(shared(int)) z;
2439 static assert(is(typeof(y) == typeof(z))); // fail!
2440 }
2441
2442 /************************************/
2443 // 6338, 6922
2444
2445 alias int T;
2446
2447 static assert(is( immutable( T ) == immutable(T) ));
2448 static assert(is( immutable( const(T)) == immutable(T) )); // 6922
2449 static assert(is( immutable(shared(T)) == immutable(T) ));
2450 static assert(is( immutable( inout(T)) == immutable(T) ));
2451 static assert(is( immutable(T) == immutable(T) ));
2452 static assert(is( const(immutable(T)) == immutable(T) )); // 6922
2453 static assert(is( shared(immutable(T)) == immutable(T) )); // 6338
2454 static assert(is( inout(immutable(T)) == immutable(T) ));
2455
2456 static assert(is( immutable(shared(const(T))) == immutable(T) ));
2457 static assert(is( immutable(const(shared(T))) == immutable(T) ));
2458 static assert(is( shared(immutable(const(T))) == immutable(T) ));
2459 static assert(is( shared(const(immutable(T))) == immutable(T) ));
2460 static assert(is( const(shared(immutable(T))) == immutable(T) ));
2461 static assert(is( const(immutable(shared(T))) == immutable(T) ));
2462
2463 static assert(is( immutable(shared(inout(T))) == immutable(T) ));
2464 static assert(is( immutable(inout(shared(T))) == immutable(T) ));
2465 static assert(is( shared(immutable(inout(T))) == immutable(T) ));
2466 static assert(is( shared(inout(immutable(T))) == immutable(T) ));
2467 static assert(is( inout(shared(immutable(T))) == immutable(T) ));
2468 static assert(is( inout(immutable(shared(T))) == immutable(T) ));
2469
2470 /************************************/
2471 // 6912
2472
test6912()2473 void test6912()
2474 {
2475 // From To
2476 static assert( is( int [] : int [] ));
2477 static assert(!is( inout(int []) : int [] ));
2478 static assert(!is( int [] : inout(int []) ));
2479 static assert( is( inout(int []) : inout(int []) ));
2480
2481 static assert( is( int [] : const(int)[] ));
2482 static assert( is( inout(int []) : const(int)[] ));
2483 static assert(!is( int [] : inout(const(int)[]) ));
2484 static assert( is( inout(int []) : inout(const(int)[]) ));
2485
2486 static assert( is( const(int)[] : const(int)[] ));
2487 static assert( is( inout(const(int)[]) : const(int)[] ));
2488 static assert(!is( const(int)[] : inout(const(int)[]) ));
2489 static assert( is( inout(const(int)[]) : inout(const(int)[]) ));
2490
2491 static assert( is( immutable(int)[] : const(int)[] ));
2492 static assert( is( inout(immutable(int)[]) : const(int)[] ));
2493 static assert( is( immutable(int)[] : inout(const(int)[]) ));
2494 static assert( is( inout(immutable(int)[]) : inout(const(int)[]) ));
2495
2496 static assert( is( immutable(int)[] : immutable(int)[] ));
2497 static assert( is( inout(immutable(int)[]) : immutable(int)[] ));
2498 static assert( is( immutable(int)[] : inout(immutable(int)[]) ));
2499 static assert( is( inout(immutable(int)[]) : inout(immutable(int)[]) ));
2500
2501 static assert( is( inout(int)[] : inout(int)[] ));
2502 static assert( is( inout(inout(int)[]) : inout(int)[] ));
2503 static assert( is( inout(int)[] : inout(inout(int)[]) ));
2504 static assert( is( inout(inout(int)[]) : inout(inout(int)[]) ));
2505
2506 static assert( is( inout(int)[] : const(int)[] ));
2507 static assert( is( inout(inout(int)[]) : const(int)[] ));
2508 static assert( is( inout(int)[] : inout(const(int)[]) ));
2509 static assert( is( inout(inout(int)[]) : inout(const(int)[]) ));
2510
2511 // From To
2512 static assert( is( int [int] : int [int] ));
2513 static assert(!is( inout(int [int]) : int [int] ));
2514 static assert(!is( int [int] : inout(int [int]) ));
2515 static assert( is( inout(int [int]) : inout(int [int]) ));
2516
2517 static assert( is( int [int] : const(int)[int] ));
2518 static assert(!is( inout(int [int]) : const(int)[int] ));
2519 static assert(!is( int [int] : inout(const(int)[int]) ));
2520 static assert( is( inout(int [int]) : inout(const(int)[int]) ));
2521
2522 static assert( is( const(int)[int] : const(int)[int] ));
2523 static assert(!is( inout(const(int)[int]) : const(int)[int] ));
2524 static assert(!is( const(int)[int] : inout(const(int)[int]) ));
2525 static assert( is( inout(const(int)[int]) : inout(const(int)[int]) ));
2526
2527 static assert( is( immutable(int)[int] : const(int)[int] ));
2528 static assert(!is( inout(immutable(int)[int]) : const(int)[int] ));
2529 static assert(!is( immutable(int)[int] : inout(const(int)[int]) ));
2530 static assert( is( inout(immutable(int)[int]) : inout(const(int)[int]) ));
2531
2532 static assert( is( immutable(int)[int] : immutable(int)[int] ));
2533 static assert(!is( inout(immutable(int)[int]) : immutable(int)[int] ));
2534 static assert(!is( immutable(int)[int] : inout(immutable(int)[int]) ));
2535 static assert( is( inout(immutable(int)[int]) : inout(immutable(int)[int]) ));
2536
2537 static assert( is( inout(int)[int] : inout(int)[int] ));
2538 static assert(!is( inout(inout(int)[int]) : inout(int)[int] ));
2539 static assert(!is( inout(int)[int] : inout(inout(int)[int]) ));
2540 static assert( is( inout(inout(int)[int]) : inout(inout(int)[int]) ));
2541
2542 static assert( is( inout(int)[int] : const(int)[int] ));
2543 static assert(!is( inout(inout(int)[int]) : const(int)[int] ));
2544 static assert(!is( inout(int)[int] : inout(const(int)[int]) ));
2545 static assert( is( inout(inout(int)[int]) : inout(const(int)[int]) ));
2546
2547 // Regression check
2548 static assert( is( const(int)[] : const(int[]) ) );
2549
2550 // From To
2551 static assert( is( int * : int * ));
2552 static assert(!is( inout(int *) : int * ));
2553 static assert(!is( int * : inout(int *) ));
2554 static assert( is( inout(int *) : inout(int *) ));
2555
2556 static assert( is( int * : const(int)* ));
2557 static assert( is( inout(int *) : const(int)* ));
2558 static assert(!is( int * : inout(const(int)*) ));
2559 static assert( is( inout(int *) : inout(const(int)*) ));
2560
2561 static assert( is( const(int)* : const(int)* ));
2562 static assert( is( inout(const(int)*) : const(int)* ));
2563 static assert(!is( const(int)* : inout(const(int)*) ));
2564 static assert( is( inout(const(int)*) : inout(const(int)*) ));
2565
2566 static assert( is( immutable(int)* : const(int)* ));
2567 static assert( is( inout(immutable(int)*) : const(int)* ));
2568 static assert( is( immutable(int)* : inout(const(int)*) ));
2569 static assert( is( inout(immutable(int)*) : inout(const(int)*) ));
2570
2571 static assert( is( immutable(int)* : immutable(int)* ));
2572 static assert( is( inout(immutable(int)*) : immutable(int)* ));
2573 static assert( is( immutable(int)* : inout(immutable(int)*) ));
2574 static assert( is( inout(immutable(int)*) : inout(immutable(int)*) ));
2575
2576 static assert( is( inout(int)* : inout(int)* ));
2577 static assert( is( inout(inout(int)*) : inout(int)* ));
2578 static assert( is( inout(int)* : inout(inout(int)*) ));
2579 static assert( is( inout(inout(int)*) : inout(inout(int)*) ));
2580
2581 static assert( is( inout(int)* : const(int)* ));
2582 static assert( is( inout(inout(int)*) : const(int)* ));
2583 static assert( is( inout(int)* : inout(const(int)*) ));
2584 static assert( is( inout(inout(int)*) : inout(const(int)*) ));
2585 }
2586
2587 /************************************/
2588 // 6930
2589
test6930a()2590 void test6930a()
2591 {
2592 inout(const int) f1(inout(const int) i) { return i; }
2593 int mi;
2594 const int ci;
2595 immutable int ii;
2596 static assert(is(typeof(f1(mi)) == const(int)));
2597 static assert(is(typeof(f1(ci)) == const(int)));
2598 static assert(is(typeof(f1(ii)) == immutable(int)));
2599
2600 inout(const int)* f2(inout(const int)* p) { return p; }
2601 int * mp;
2602 const(int)* cp;
2603 immutable(int)* ip;
2604 static assert(is(typeof(f2(mp)) == const(int)*));
2605 static assert(is(typeof(f2(cp)) == const(int)*));
2606 static assert(is(typeof(f2(ip)) == immutable(int)*));
2607
2608 inout(const int)[] f3(inout(const int)[] a) { return a; }
2609 int [] ma;
2610 const(int)[] ca;
2611 immutable(int)[] ia;
2612 static assert(is(typeof(f3(ma)) == const(int)[]));
2613 static assert(is(typeof(f3(ca)) == const(int)[]));
2614 static assert(is(typeof(f3(ia)) == immutable(int)[]));
2615
2616 inout(const int[1]) f4(inout(const int[1]) sa) { return sa; }
2617 int[1] msa;
2618 const int[1] csa;
2619 immutable int[1] isa;
2620 static assert(is(typeof(f4(msa)) == const(int)[1]));
2621 static assert(is(typeof(f4(csa)) == const(int)[1]));
2622 static assert(is(typeof(f4(isa)) == immutable(int)[1]));
2623
2624 inout(const int)[string] f5(inout(const int)[string] aa) { return aa; }
2625 int [string] maa;
2626 const(int)[string] caa;
2627 immutable(int)[string] iaa;
2628 static assert(is(typeof(f5(maa)) == const(int)[string]));
2629 static assert(is(typeof(f5(caa)) == const(int)[string]));
2630 static assert(is(typeof(f5(iaa)) == immutable(int)[string]));
2631 }
2632
foo6930(inout (int)[]x)2633 inout(const(int[])) foo6930(inout(int)[] x)
2634 {
2635 bool condition = cast(bool)(x.length / 2);
2636 return condition ? x : new immutable(int[])(2);
2637 }
2638
2639 void test6930b(inout int = 0)
2640 {
2641 alias T1 = inout(shared(const(int)));
2642 static assert(T1.stringof == "shared(inout(const(int)))");
2643 static assert(is(T1 == shared) && is(T1 == const) && is(T1 == inout));
2644
2645 alias T2 = const(shared(inout(int)[]));
2646 static assert(T2.stringof == "shared(const(inout(int)[]))");
2647 static assert(is(T2 == shared) && is(T2 == const) && !is(T2 == inout) && is(typeof(T2.init[0]) == inout));
2648
2649 int [] ma;
2650 const(int)[] ca;
2651 immutable(int)[] ia;
2652 inout(int)[] wa;
2653 static assert(is(typeof(foo6930(ma)) == const int[]));
2654 static assert(is(typeof(foo6930(ca)) == const int[]));
2655 static assert(is(typeof(foo6930(ia)) == immutable int[]));
2656 static assert(is(typeof(foo6930(wa)) == inout const int[]));
2657 }
2658
2659 /************************************/
2660 // 11868
2661
f11868(A...)2662 void f11868(A...)(A) { }
2663
g11868(inout (const (int))[]arr)2664 void g11868(inout(const(int))[] arr)
2665 {
2666 f11868(arr[0]);
2667 }
2668
test11868()2669 void test11868()
2670 {
2671 auto arr = [1,2,3];
2672 g11868(arr);
2673 }
2674
2675 /************************************/
2676 // 11924
2677
localize11924(StringType)2678 inout(StringType) localize11924(StringType)(inout StringType str, string locale)
2679 {
2680 return str;
2681 }
2682
2683 struct S11924
2684 {
menuItem_1S119242685 static menuItem_1(ARGS...)()
2686 {
2687 enum itemTitle = ARGS;
2688 }
2689
content_left_1S119242690 static content_left_1()
2691 {
2692 menuItem!(localize11924("Home", ""));
2693 }
2694 alias menuItem = menuItem_1;
2695 }
2696
2697 /************************************/
2698 // 11966
2699
inout(char)2700 inout(char)[] stripped11966 (inout(char)[] path)
2701 {
2702 return path;
2703 }
2704
2705 struct PathParser11966
2706 {
inoutPathParser119662707 inout(const(char))[] path() inout
2708 {
2709 return null;
2710 }
2711
inoutPathParser119662712 inout(const(char))[] pop() inout
2713 {
2714 return stripped11966(path);
2715 }
2716 }
2717
test11966()2718 void test11966()
2719 {
2720 auto a = PathParser11966().pop();
2721 }
2722
2723 /************************************/
2724 // 14788
2725
make14788(K,V)2726 auto make14788(K, V)(inout V[K] aa)
2727 {
2728 static struct Result
2729 {
2730 V[K] aa;
2731 ref front() inout { return aa[1]; }
2732 }
2733 return inout Result(aa);
2734 }
2735
test14788()2736 void test14788()
2737 {
2738 int[int] aa = [1:1];
2739 make14788(aa).front();
2740 }
2741
2742 /************************************/
2743 // 12089
2744
foo12089(inout (char[])a)2745 void foo12089(inout(char[]) a)
2746 {
2747 validate12089(a);
2748 }
validate12089(S)2749 void validate12089(S)(in S str)
2750 {
2751 decodeImpl12089(str);
2752 }
decodeImpl12089(S)2753 void decodeImpl12089(S)(auto ref S str)
2754 {}
2755
2756 /************************************/
2757 // 12524
2758
dup12524(inout (const (int))val)2759 inout(int) dup12524(inout(const(int)) val)
2760 {
2761 return val;
2762 }
2763
test12524(inout (int))2764 void test12524(inout(int))
2765 {
2766 inout(const(int)) val;
2767
2768 auto bug = dup12524(val);
2769
2770 static assert(is(typeof(bug) == inout(int)));
2771 }
2772
2773 /************************************/
2774 // 6941
2775
2776 static assert((const(shared(int[])[])).stringof == "const(shared(int[])[])"); // fail
2777 static assert((const(shared(int[])[])).stringof != "const(shared(const(int[]))[])"); // fail
2778
2779 static assert((inout(shared(int[])[])).stringof == "inout(shared(int[])[])"); // fail
2780 static assert((inout(shared(int[])[])).stringof != "inout(shared(inout(int[]))[])"); // fail
2781
2782 /************************************/
2783 // 6872
2784
2785 static assert((shared(inout(int)[])).stringof == "shared(inout(int)[])");
2786 static assert((shared(inout(const(int)[]))).stringof == "shared(inout(const(int)[]))");
2787 static assert((shared(inout(const(int)[])[])).stringof == "shared(inout(const(int)[])[])");
2788 static assert((shared(inout(const(immutable(int)[])[])[])).stringof == "shared(inout(const(immutable(int)[])[])[])");
2789
2790 /************************************/
2791 // 6939
2792
test6939()2793 void test6939()
2794 {
2795 shared int* x;
2796 immutable int* y;
2797 const int* z;
2798 static assert( is(typeof(1?x:y) == shared(const(int))*)); // fail
2799 static assert(!is(typeof(1?x:y) == const(int)*)); // fail
2800 static assert(!is(typeof(1?x:z))); // fail
2801
2802 shared int[] a;
2803 immutable int[] b;
2804 const int[] c;
2805 static assert( is(typeof(1?a:b) == shared(const(int))[])); // pass (ok)
2806 static assert(!is(typeof(1?a:b) == const(int)[])); // pass (ok)
2807 static assert(!is(typeof(1?a:c))); // fail
2808 }
2809
2810 /************************************/
2811 // 6940
2812
test6940()2813 void test6940()
2814 {
2815 immutable(int*)* x;
2816 int** y;
2817 static assert(is(typeof(x) : const(int*)*)); // ok
2818 static assert(is(typeof(y) : const(int*)*)); // ok
2819 static assert(is(typeof(1?x:y) == const(int*)*));
2820
2821 immutable(int[])[] a;
2822 int[][] b;
2823 static assert(is(typeof(a) : const(int[])[])); // ok
2824 static assert(is(typeof(b) : const(int[])[])); // ok
2825 static assert(is(typeof(1?a:b) == const(int[])[]));
2826
2827 immutable(int)** v;
2828 int** w;
2829 static assert(is(typeof(1?v:w) == const(int*)*));
2830 }
2831
2832 /************************************/
2833 // 6982
2834
test6982()2835 void test6982()
2836 {
2837 alias int Bla;
2838 immutable(Bla[string]) ifiles = ["a":1, "b":2, "c":3];
2839 static assert(!__traits(compiles, { immutable(Bla)[string] files = ifiles; })); // (1)
2840 static assert(!__traits(compiles, { ifiles.remove ("a"); })); // (2)
2841
2842 immutable(int)[int] maa;
2843 const(immutable(int)[int]) caa;
2844 immutable( int [int]) iaa;
2845 static assert(!__traits(compiles, { maa = iaa; }));
2846 static assert(!__traits(compiles, { maa = caa; }));
2847 }
2848
2849 /************************************/
2850 // 7038
2851
2852 static assert(is(S7038 == const));
2853 const struct S7038{ int x; }
2854 static assert(is(S7038 == const));
2855
2856 shared struct S7038b{ int x; }
2857 static assert(is(S7038b == shared));
2858
2859 immutable struct S7038c{ int x; }
2860 static assert(is(S7038c == immutable));
2861
2862 static assert(!is(C7038 == const));
2863 const class C7038{ int x; }
2864 static assert(!is(C7038 == const));
2865
test7038()2866 void test7038()
2867 {
2868 S7038 s;
2869 static assert(is(typeof(s) == const));
2870 static assert(is(typeof(s.x) == const int));
2871
2872 C7038 c;
2873 static assert(!is(typeof(c) == const));
2874 static assert(is(typeof(c.x) == const int));
2875 }
2876
2877 /************************************/
2878 // 7105
2879
copy(inout (int)** tgt,inout (int)* src)2880 void copy(inout(int)** tgt, inout(int)* src){ *tgt = src; }
2881
test7105()2882 void test7105()
2883 {
2884 int* pm;
2885 int m;
2886 copy(&pm, &m);
2887 assert(pm == &m);
2888
2889 const(int)* pc;
2890 const(int) c;
2891 copy(&pc, &c);
2892 assert(pc == &c);
2893
2894 immutable(int)* pi;
2895 immutable(int) i;
2896 copy(&pi, &i);
2897 assert(pi == &i);
2898
2899 static assert(!__traits(compiles, copy(&pm, &c)));
2900 static assert(!__traits(compiles, copy(&pm, &i)));
2901
2902 copy(&pc, &m);
2903 assert(pc == &m);
2904 copy(&pc, &i);
2905 assert(pc == &i);
2906
2907 static assert(!__traits(compiles, copy(&pi, &m)));
2908 static assert(!__traits(compiles, copy(&pi, &c)));
2909 }
2910
2911 /************************************/
2912 // 7202
2913
test7202()2914 void test7202()
2915 {
2916 void writeln(string s) @system { printf("%.*s\n", s.length, s.ptr); }
2917 void delegate() @system x = { writeln("I am @system"); };
2918 void delegate() @safe y = { };
2919 auto px = &x;
2920 auto py = &y;
2921 static assert(!__traits(compiles, px = py)); // accepts-invalid
2922 *px = x;
2923 y(); // "I am @system" -> no output, OK
2924 }
2925
2926 /************************************/
2927 // 7554
2928
outer7554(T)2929 T outer7554(T)(immutable T function(T) pure foo) pure {
2930 pure int inner() {
2931 return foo(5);
2932 }
2933 return inner();
2934 }
sqr7554(int x)2935 int sqr7554(int x) pure {
2936 return x * x;
2937 }
test7554()2938 void test7554()
2939 {
2940 assert(outer7554(&sqr7554) == 25);
2941
2942 immutable(int function(int) pure) ifp = &sqr7554;
2943 }
2944
2945 /************************************/
2946
empty(T)2947 bool empty(T)(in T[] a)
2948 {
2949 assert(is(T == shared(string)));
2950 return false;
2951 }
2952
2953
test7518()2954 void test7518() {
2955 shared string[] stuff;
2956 stuff.empty();
2957 }
2958
2959 /************************************/
2960 // 7669
2961
2962 shared(inout U)[n] id7669(U, size_t n)( shared(inout U)[n] );
test7669()2963 void test7669()
2964 {
2965 static assert(is(typeof( id7669((shared(int)[3]).init)) == shared(int)[3]));
2966 }
2967
2968 /************************************/
2969 // 7757
2970
foo7757a(int x,lazy inout (int)def)2971 inout(int) foo7757a(int x, lazy inout(int) def) { return def; }
inout(int)2972 inout(int)[] foo7757b(int x, lazy inout(int)[] def) { return def; }
inout(int)2973 inout(int)[int] foo7757c(int x, lazy inout(int)[int] def) { return def; }
2974
bar7757a(T)2975 inout(T) bar7757a(T)(T x, lazy inout(T) def) { return def; }
inout(T)2976 inout(T)[] bar7757b(T)(T x, lazy inout(T)[] def) { return def; }
inout(T)2977 inout(T)[T] bar7757c(T)(T x, lazy inout(T)[T] def) { return def; }
2978
get7757(lazy inout (Object)defVal)2979 inout(Object) get7757(lazy inout(Object) defVal) { return null; }
2980
test7757()2981 void test7757()
2982 {
2983 int mx1 = foo7757a(1,2);
2984 const(int) cx1 = foo7757a(1,2);
2985 int [] ma1 = foo7757b(1,[2]);
2986 const(int)[] ca1 = foo7757b(1,[2]);
2987 int [int] maa1 = foo7757c(1,[2:3]);
2988 const(int)[int] caa1 = foo7757c(1,[2:3]);
2989
2990 int mx2 = bar7757a(1,2);
2991 const(int) cx2 = bar7757a(1,2);
2992 int [] ma2 = bar7757b(1,[2]);
2993 const(int)[] ca2 = bar7757b(1,[2]);
2994 int [int] maa2 = bar7757c(1,[2:3]);
2995 const(int)[int] caa2 = bar7757c(1,[2:3]);
2996
2997 Object defObj = null;
2998 auto resObj = get7757(defObj);
2999 }
3000
3001 /************************************/
3002 // 8098
3003
3004 class Outer8098
3005 {
3006 int i = 6;
3007
3008 class Inner
3009 {
3010 int y=0;
3011
foo()3012 void foo() const
3013 {
3014 static assert(is(typeof(this.outer) == const(Outer8098)));
3015 static assert(is(typeof(i) == const(int)));
3016 static assert(!__traits(compiles, ++i));
3017 }
3018 }
3019
3020 Inner inner;
3021
this()3022 this()
3023 {
3024 inner = new Inner;
3025 }
3026 }
3027
test8098()3028 void test8098()
3029 {
3030 const(Outer8098) x = new Outer8098();
3031 static assert(is(typeof(x) == const(Outer8098)));
3032 static assert(is(typeof(x.inner) == const(Outer8098.Inner)));
3033 }
3034
3035 /************************************/
3036 // 8099
3037
test8099()3038 void test8099()
3039 {
3040 static class Outer
3041 {
3042 class Inner {}
3043 }
3044
3045 auto m = new Outer;
3046 auto c = new const(Outer);
3047 auto i = new immutable(Outer);
3048
3049 auto mm = m.new Inner; // m -> m OK
3050 auto mc = m.new const(Inner); // m -> c OK
3051 static assert(!__traits(compiles, {
3052 auto mi = m.new immutable(Inner); // m -> i bad
3053 }));
3054
3055 static assert(!__traits(compiles, {
3056 auto cm = c.new Inner; // c -> m bad
3057 }));
3058 auto cc = c.new const(Inner); // c -> c OK
3059 static assert(!__traits(compiles, {
3060 auto ci = c.new immutable(Inner); // c -> i bad
3061 }));
3062
3063 static assert(!__traits(compiles, {
3064 auto im = i.new Inner; // i -> m bad
3065 }));
3066 auto ic = i.new const(Inner); // i -> c OK
3067 auto ii = i.new immutable(Inner); // i -> i OK
3068 }
3069
3070 /************************************/
3071 // 8201
3072
test8201()3073 void test8201()
3074 {
3075 uint[2] msa;
3076 immutable uint[2] isa = msa;
3077
3078 ubyte[] buffer = [0, 1, 2, 3, 4, 5];
3079 immutable ubyte[4] iArr = buffer[0 .. 4];
3080 }
3081
3082 /************************************/
3083 // 8212
3084
3085 struct S8212 { int x; }
3086
3087 shared S8212 s8212;
3088
3089 shared int x8212;
3090
test8212()3091 void test8212()
3092 {
3093 int y = x8212;
3094 S8212 s2 = s8212;
3095 }
3096
3097 /************************************/
3098 // 8366
3099
3100 class B8366
3101 {
foo(in Object o)3102 bool foo(in Object o) const { return true; }
3103 }
3104
3105 class C8366a : B8366
3106 {
foo(in Object o)3107 bool foo(in Object o) { return true; }
3108 override
foo(in Object o)3109 bool foo(in Object o) const { return false; }
foo(in Object o)3110 bool foo(in Object o) immutable { return true; }
foo(in Object o)3111 bool foo(in Object o) shared { return true; }
foo(in Object o)3112 bool foo(in Object o) shared const { return true; }
3113 }
3114
3115 class C8366b : B8366
3116 {
foo(in Object o)3117 bool foo(in Object o) { return false; }
3118 alias super.foo foo;
foo(in Object o)3119 bool foo(in Object o) immutable { return false; }
foo(in Object o)3120 bool foo(in Object o) shared { return false; }
foo(in Object o)3121 bool foo(in Object o) shared const { return false; }
3122 }
3123
test8366()3124 void test8366()
3125 {
3126 {
3127 C8366a mca = new C8366a();
3128 const C8366a cca = new C8366a();
3129 B8366 mb = mca;
3130 const B8366 cb = cca;
3131 assert(mca.foo(null) == true);
3132 assert(cca.foo(null) == false);
3133 assert(mb .foo(null) == false);
3134 assert(cb .foo(null) == false);
3135 }
3136 {
3137 C8366b mcb = new C8366b();
3138 const C8366b ccb = new C8366b();
3139 B8366 mb = mcb;
3140 const B8366 cb = ccb;
3141 assert(mcb.foo(null) == false);
3142 assert(ccb.foo(null) == true);
3143 assert(mb .foo(null) == true);
3144 assert(cb .foo(null) == true);
3145 }
3146 }
3147
3148 /************************************/
3149 // 8408
3150
hasMutableIndirection8408(T)3151 template hasMutableIndirection8408(T)
3152 {
3153 template Unqual(T)
3154 {
3155 static if (is(T U == shared(const U))) alias U Unqual;
3156 else static if (is(T U == const U )) alias U Unqual;
3157 else static if (is(T U == immutable U )) alias U Unqual;
3158 else static if (is(T U == inout U )) alias U Unqual;
3159 else static if (is(T U == shared U )) alias U Unqual;
3160 else alias T Unqual;
3161 }
3162
3163 enum hasMutableIndirection8408 = !is(typeof({ Unqual!T t = void; immutable T u = t; }));
3164 }
3165 static assert(!hasMutableIndirection8408!(int));
3166 static assert(!hasMutableIndirection8408!(int[3]));
3167 static assert( hasMutableIndirection8408!(Object));
3168
dup8408(E)3169 auto dup8408(E)(inout(E)[] arr) pure @trusted
3170 {
3171 static if (hasMutableIndirection8408!E)
3172 {
3173 auto copy = new E[](arr.length);
3174 copy[] = cast(E[])arr[]; // assume constant
3175 return cast(inout(E)[])copy; // assume constant
3176 }
3177 else
3178 {
3179 auto copy = new E[](arr.length);
3180 copy[] = arr[];
3181 return copy;
3182 }
3183 }
3184
test8408()3185 void test8408()
3186 {
3187 void test(E, bool constConv)()
3188 {
3189 E[] marr = [E.init, E.init, E.init];
3190 immutable E[] iarr = [E.init, E.init, E.init];
3191
3192 E[] m2m = marr.dup8408(); assert(m2m == marr);
3193 immutable E[] i2i = iarr.dup8408(); assert(i2i == iarr);
3194
3195 static if (constConv)
3196 { // If dup() hss strong purity, implicit conversion is allowed
3197 immutable E[] m2i = marr.dup8408(); assert(m2i == marr);
3198 E[] i2m = iarr.dup8408(); assert(i2m == iarr);
3199 }
3200 else
3201 {
3202 static assert(!is(typeof({ immutable E[] m2i = marr.dup8408(); })));
3203 static assert(!is(typeof({ E[] i2m = iarr.dup8408(); })));
3204 }
3205 }
3206
3207 class C {}
3208 struct S1 { long n; }
3209 struct S2 { int* p; }
3210 struct T1 { S1 s; }
3211 struct T2 { S2 s; }
3212 struct T3 { S1 s1; S2 s2; }
3213
3214 test!(int , true )();
3215 test!(int[3], true )();
3216 test!(C , false)();
3217 test!(S1 , true )();
3218 test!(S2 , false)();
3219 test!(T1 , true )();
3220 test!(T2 , false)();
3221 test!(T3 , false)();
3222 }
3223
3224 /************************************/
3225 // 8688
3226
test8688()3227 void test8688()
3228 {
3229 alias TypeTuple!(int) T;
3230 foreach (i; TypeTuple!(0))
3231 {
3232 alias const(T[i]) X;
3233 static assert(!is(X == int)); // fails
3234 static assert( is(X == const(int))); // fails
3235 }
3236 }
3237
3238 /************************************/
3239 // 10946 (regression by fixing bug 8688, from 2.061)
3240
3241 enum xlen10946 = 4;
3242 alias immutable(char)[xlen10946] e3;
3243 alias immutable(char[xlen10946]) e4; // NG -> OK
3244 immutable vlen10946 = 4;
3245 alias immutable(char)[vlen10946] i3;
3246 alias immutable(char[vlen10946]) i4; // NG -> OK
3247
3248 /************************************/
3249 // 9046
3250
test9046()3251 void test9046()
3252 {
3253 foreach (T; TypeTuple!(byte, ubyte, short, ushort, int, uint, long, ulong, char, wchar, dchar,
3254 float, double, real, ifloat, idouble, ireal, cfloat, cdouble, creal))
3255 foreach (U; TypeTuple!(T, const T, immutable T, shared T, shared const T, inout T, shared inout T))
3256 {
3257 static assert(is(typeof(U.init) == U));
3258 }
3259
3260 foreach (T; TypeTuple!(int[], const(char)[], immutable(string[]), shared(const(int)[])[],
3261 int[1], const(char)[1], immutable(string[1]), shared(const(int)[1])[],
3262 int[int], const(char)[long], immutable(string[string]), shared(const(int)[double])[]))
3263 foreach (U; TypeTuple!(T, const T, immutable T, shared T, shared const T, inout T, shared inout T))
3264 {
3265 static assert(is(typeof(U.init) == U));
3266 }
3267
3268 int i;
3269 enum E { x, y }
3270 static struct S {}
3271 static class C {}
3272 struct NS { void f(){ i++; } }
3273 class NC { void f(){ i++; } }
3274 foreach (T; TypeTuple!(E, S, C, NS, NC))
3275 foreach (U; TypeTuple!(T, const T, immutable T, shared T, shared const T, inout T, shared inout T))
3276 {
3277 static assert(is(typeof(U.init) == U));
3278 }
3279
3280 alias TL = TypeTuple!(int, string, int[int]);
3281 foreach (U; TypeTuple!(TL, const TL, immutable TL, shared TL, shared const TL, inout TL, shared inout TL))
3282 {
3283 static assert(is(typeof(U.init) == U));
3284 }
3285 }
3286
3287 /************************************/
3288 // 9090
3289
test9090()3290 void test9090()
3291 {
3292 void test1(T)(auto ref const T[] val) {}
3293
3294 string a;
3295 test1(a);
3296 }
3297
3298 /************************************/
3299 // 9461
3300
test9461()3301 void test9461()
3302 {
3303 class A {}
3304 class B : A {}
3305
3306 void conv(S, T)(ref S x) { T y = x; }
3307
3308 // should be NG
3309 static assert(!__traits(compiles, conv!(inout(B)[], inout(A)[])));
3310 static assert(!__traits(compiles, conv!(int[inout(B)], int[inout(A)])));
3311 static assert(!__traits(compiles, conv!(inout(B)[int], inout(A)[int])));
3312 static assert(!__traits(compiles, conv!(inout(B)*, inout(A)*)));
3313 static assert(!__traits(compiles, conv!(inout(B)[1], inout(A)[])));
3314
3315 // should be OK
3316 static assert( __traits(compiles, conv!(inout(B), inout(A))));
3317 }
3318
3319 /************************************/
3320
3321 struct S9209 { int x; }
3322
bar9209(const S9209 *)3323 void bar9209(const S9209*) {}
3324
test9209()3325 void test9209() {
3326 const f = new S9209(1);
3327 bar9209(f);
3328 }
3329
3330 /************************************/
3331 // 10758
3332
3333 struct X10758
3334 {
3335 static:
inoutX107583336 inout(int) screwUpVal(ref inout(int) wx) { return wx; }
inoutX107583337 ref inout(int) screwUpRef(ref inout(int) wx) { return wx; }
inoutX107583338 inout(int)* screwUpPtr(ref inout(int) wx) { return &wx; }
inoutX107583339 inout(int)[] screwUpArr(ref inout(int) wx) { return (&wx)[0 .. 1]; }
3340 }
3341
3342 struct S10758
3343 {
3344 int x;
screwUpVal(ref inout (int)_)3345 inout(int) screwUpVal(ref inout(int) _) inout { return x; }
inout(int)3346 ref inout(int) screwUpRef(ref inout(int) _) inout { return x; }
inout(int)3347 inout(int)* screwUpPtr(ref inout(int) _) inout { return &x; }
inout(int)3348 inout(int)[] screwUpArr(ref inout(int) _) inout { return (&x)[0 .. 1]; }
3349 }
3350
test10758(ref inout (int)wx,inout (int)* wp,inout (int)[]wa,inout (S10758)ws)3351 void test10758(ref inout(int) wx, inout(int)* wp, inout(int)[] wa, inout(S10758) ws)
3352 {
3353 inout(int) screwUpVal(inout(int) _) { return wx; }
3354 ref inout(int) screwUpRef(inout(int) _) { return wx; }
3355 inout(int)* screwUpPtr(inout(int) _) { return &wx; }
3356 inout(int)[] screwUpArr(inout(int) _) { return (&wx)[0 .. 1]; }
3357
3358 struct NS
3359 {
3360 inout(int) screwUpVal() inout { return wx; }
3361 ref inout(int) screwUpRef() inout { return wx; }
3362 inout(int)* screwUpPtr() inout { return &wx; }
3363 inout(int)[] screwUpArr() inout { return (&wx)[0 .. 1]; }
3364 }
3365
3366 int mx = 1;
3367 const(int) cx = 1;
3368 immutable(int) ix = 1;
3369
3370 // nested inout function may return an inout reference of the context,
3371 // so substitude inout to mutable or immutable should be disallowed.
3372 {
3373 // value return does not leak any inout reference, so safe.
3374 screwUpVal(mx);
3375 screwUpVal(ix);
3376 screwUpVal(wx);
3377 screwUpVal(cx);
3378
3379 static assert(!__traits(compiles, screwUpRef(mx)));
3380 static assert(!__traits(compiles, screwUpRef(ix)));
3381 screwUpRef(wx);
3382 screwUpRef(cx);
3383
3384 static assert(!__traits(compiles, screwUpPtr(mx)));
3385 static assert(!__traits(compiles, screwUpPtr(ix)));
3386 screwUpPtr(wx);
3387 screwUpPtr(cx);
3388
3389 static assert(!__traits(compiles, screwUpArr(mx)));
3390 static assert(!__traits(compiles, screwUpArr(ix)));
3391 screwUpArr(cx);
3392 screwUpArr(wx);
3393 }
3394
3395 // inout method of the nested struct may return an inout reference of the context,
3396 {
3397 ( NS()).screwUpVal();
3398 (immutable NS()).screwUpVal();
3399 ( inout NS()).screwUpVal();
3400 ( const NS()).screwUpVal();
3401
3402 static assert(!__traits(compiles, ( NS()).screwUpRef()));
3403 static assert(!__traits(compiles, (immutable NS()).screwUpRef()));
3404 (inout NS()).screwUpRef();
3405 (const NS()).screwUpRef();
3406
3407 static assert(!__traits(compiles, ( NS()).screwUpPtr()));
3408 static assert(!__traits(compiles, (immutable NS()).screwUpPtr()));
3409 (inout NS()).screwUpPtr();
3410 (const NS()).screwUpPtr();
3411
3412 static assert(!__traits(compiles, ( NS()).screwUpArr()));
3413 static assert(!__traits(compiles, (immutable NS()).screwUpArr()));
3414 (inout NS()).screwUpArr();
3415 (const NS()).screwUpArr();
3416 }
3417
3418 // function pointer holds no context, so there's no screw up.
3419 {
3420 auto fp_screwUpVal = &X10758.screwUpVal;
3421 fp_screwUpVal(mx);
3422 fp_screwUpVal(ix);
3423 fp_screwUpVal(wx);
3424 fp_screwUpVal(cx);
3425
3426 auto fp_screwUpRef = &X10758.screwUpRef;
3427 fp_screwUpRef(mx);
3428 fp_screwUpRef(ix);
3429 fp_screwUpRef(wx);
3430 fp_screwUpRef(cx);
3431
3432 auto fp_screwUpPtr = &X10758.screwUpVal;
3433 fp_screwUpPtr(mx);
3434 fp_screwUpPtr(ix);
3435 fp_screwUpPtr(wx);
3436 fp_screwUpPtr(cx);
3437
3438 auto fp_screwUpArr = &X10758.screwUpVal;
3439 fp_screwUpArr(mx);
3440 fp_screwUpArr(ix);
3441 fp_screwUpArr(wx);
3442 fp_screwUpArr(cx);
3443 }
3444
3445 // inout delegate behaves same as nested functions.
3446 {
3447 auto dg_screwUpVal = &ws.screwUpVal;
3448 dg_screwUpVal(mx);
3449 dg_screwUpVal(ix);
3450 dg_screwUpVal(wx);
3451 dg_screwUpVal(cx);
3452
3453 auto dg_screwUpRef = &ws.screwUpRef;
3454 static assert(!__traits(compiles, dg_screwUpRef(mx)));
3455 static assert(!__traits(compiles, dg_screwUpRef(ix)));
3456 dg_screwUpRef(wx);
3457 dg_screwUpRef(cx);
3458
3459 auto dg_screwUpPtr = &ws.screwUpPtr;
3460 static assert(!__traits(compiles, dg_screwUpPtr(mx)));
3461 static assert(!__traits(compiles, dg_screwUpPtr(ix)));
3462 dg_screwUpPtr(wx);
3463 dg_screwUpPtr(cx);
3464
3465 auto dg_screwUpArr = &ws.screwUpArr;
3466 static assert(!__traits(compiles, dg_screwUpArr(mx)));
3467 static assert(!__traits(compiles, dg_screwUpArr(ix)));
3468 dg_screwUpArr(cx);
3469 dg_screwUpArr(wx);
3470 }
3471 }
3472
3473 /************************************/
3474 // 10761
3475
inout(int)3476 inout(int)* function(inout(int)*) fptr10761(inout(int)*)
3477 {
3478 static inout(int)* screwUp(inout(int)* x) { return x; }
3479 auto fp = &screwUp;
3480 static assert(is(typeof(fp) == inout(int)* function(inout(int)*) pure nothrow @nogc @safe));
3481 return fp;
3482 }
3483
inout(int)3484 inout(int)* delegate(inout(int)*) nest10761(inout(int)* x)
3485 {
3486 inout(int)* screwUp(inout(int)* _) { return x; }
3487 auto dg = &screwUp;
3488 static assert(is(typeof(dg) == inout(int)* delegate(inout(int)*) pure nothrow @nogc @safe));
3489 return dg;
3490 }
3491
3492 struct S10761
3493 {
3494 int x;
inoutS107613495 inout(int)* screwUp() inout { return &x; }
3496 }
3497
inout(int)3498 inout(int)* delegate() inout memfn10761(inout(int)* x)
3499 {
3500 auto s = new inout S10761(1);
3501 auto dg = &s.screwUp;
3502 static assert(is(typeof(dg) == inout(int)* delegate() inout));
3503 return dg;
3504 }
3505
test10761()3506 void test10761()
3507 {
3508 int mx = 1;
3509 const(int) cx = 1;
3510 immutable(int) ix = 1;
3511
3512 // inout substitution has no effect on function pointer type
3513 {
3514 auto fp_m = fptr10761(&mx);
3515 auto fp_c = fptr10761(&cx);
3516 auto fp_i = fptr10761(&ix);
3517 alias FP = inout(int)* function(inout(int)*);
3518 static assert(is(typeof(fp_m) == FP));
3519 static assert(is(typeof(fp_c) == FP));
3520 static assert(is(typeof(fp_i) == FP));
3521 }
3522
3523 // inout substitution on delegate type should always
3524 // modify inout to const.
3525 {
3526 auto dg_m = nest10761(&mx);
3527 auto dg_c = nest10761(&cx);
3528 auto dg_i = nest10761(&ix);
3529 alias DG = const(int)* delegate(const(int)*);
3530 static assert(is(typeof(dg_m) == DG));
3531 static assert(is(typeof(dg_c) == DG));
3532 static assert(is(typeof(dg_i) == DG));
3533 }
3534
3535 // same as above
3536 {
3537 auto dg_m = memfn10761(&mx);
3538 auto dg_c = memfn10761(&cx);
3539 auto dg_i = memfn10761(&ix);
3540 alias DG = const(int)* delegate() const;
3541 static assert(is(typeof(dg_m) == DG));
3542 static assert(is(typeof(dg_c) == DG));
3543 static assert(is(typeof(dg_i) == DG));
3544 }
3545 }
3546
3547 /************************************/
3548 // 11226
3549
test11226()3550 void test11226()
3551 {
3552 typeof(null) m;
3553 const typeof(null) c = m;
3554 immutable typeof(null) i = m;
3555
3556 m = m, m = c, m = i;
3557 assert(m == c);
3558 assert(m == i);
3559 assert(c == i);
3560 static assert(is(typeof(true ? m : m) == typeof(null)));
3561 static assert(is(typeof(true ? m : c) == const typeof(null)));
3562 static assert(is(typeof(true ? m : i) == const typeof(null)));
3563 static assert(is(typeof(true ? c : m) == const typeof(null)));
3564 static assert(is(typeof(true ? c : c) == const typeof(null)));
3565 static assert(is(typeof(true ? c : i) == const typeof(null)));
3566 static assert(is(typeof(true ? i : m) == const typeof(null)));
3567 static assert(is(typeof(true ? i : c) == const typeof(null)));
3568 static assert(is(typeof(true ? i : i) == immutable typeof(null)));
3569
3570 static assert(typeof(m).stringof == "typeof(null)" );
3571 static assert(typeof(c).stringof == "const(typeof(null))");
3572 static assert(typeof(i).stringof == "immutable(typeof(null))");
3573 }
3574
3575 /************************************/
3576 // 11257
3577
3578 struct R11257
3579 {
3580 union
3581 {
3582 const(Object) original;
3583 Object stripped;
3584 }
3585 }
3586 void test11257()
3587 {
3588 const(R11257) cr;
3589 R11257 mr = cr; // Error: cannot implicitly convert expression (cr) of type const(R) to R
3590 }
3591
3592 /************************************/
3593 // 11215
3594
3595 shared(inout(void)**) f11215(inout int);
3596
3597 static assert(is(typeof(f11215(0)) == shared(void**)));
3598 static assert(is(typeof(f11215((const int).init)) == shared(const(void)**)));
3599
3600 /************************************/
3601 // 11489
3602
3603 void test11489(inout int = 0)
3604 {
3605 static class B {}
3606 static class D : B {}
3607
3608 D [] dm;
3609 const(D)[] dc;
3610 inout(D)[] dw;
3611 shared(D)[] dsm;
3612 shared(const D)[] dsc;
3613 shared(inout D)[] dsw;
3614 immutable(D)[] di;
3615
3616 static assert(!__traits(compiles, { B [] b = dm; }));
3617 static assert( __traits(compiles, { const(B)[] b = dm; }));
3618 static assert(!__traits(compiles, { inout(B)[] b = dm; }));
3619 static assert(!__traits(compiles, { shared(B)[] b = dm; }));
3620 static assert(!__traits(compiles, { shared(const B)[] b = dm; }));
3621 static assert(!__traits(compiles, { shared(inout B)[] b = dm; }));
3622 static assert(!__traits(compiles, { immutable(B)[] b = dm; }));
3623
3624 static assert(!__traits(compiles, { B [] b = dc; }));
3625 static assert( __traits(compiles, { const(B)[] b = dc; }));
3626 static assert(!__traits(compiles, { inout(B)[] b = dc; }));
3627 static assert(!__traits(compiles, { shared(B)[] b = dc; }));
3628 static assert(!__traits(compiles, { shared(const B)[] b = dc; }));
3629 static assert(!__traits(compiles, { shared(inout B)[] b = dc; }));
3630 static assert(!__traits(compiles, { immutable(B)[] b = dc; }));
3631
3632 static assert(!__traits(compiles, { B [] b = dw; }));
3633 static assert( __traits(compiles, { const(B)[] b = dw; }));
3634 static assert(!__traits(compiles, { inout(B)[] b = dw; }));
3635 static assert(!__traits(compiles, { shared(B)[] b = dw; }));
3636 static assert(!__traits(compiles, { shared(const B)[] b = dw; }));
3637 static assert(!__traits(compiles, { shared(inout B)[] b = dw; }));
3638 static assert(!__traits(compiles, { immutable(B)[] b = dw; }));
3639
3640 static assert(!__traits(compiles, { B [] b = dsm; }));
3641 static assert(!__traits(compiles, { const(B)[] b = dsm; }));
3642 static assert(!__traits(compiles, { inout(B)[] b = dsm; }));
3643 static assert(!__traits(compiles, { shared(B)[] b = dsm; }));
3644 static assert( __traits(compiles, { shared(const B)[] b = dsm; }));
3645 static assert(!__traits(compiles, { shared(inout B)[] b = dsm; }));
3646 static assert(!__traits(compiles, { immutable(B)[] b = dsm; }));
3647
3648 static assert(!__traits(compiles, { B [] b = dsc; }));
3649 static assert(!__traits(compiles, { const(B)[] b = dsc; }));
3650 static assert(!__traits(compiles, { inout(B)[] b = dsc; }));
3651 static assert(!__traits(compiles, { shared(B)[] b = dsc; }));
3652 static assert( __traits(compiles, { shared(const B)[] b = dsc; }));
3653 static assert(!__traits(compiles, { shared(inout B)[] b = dsc; }));
3654 static assert(!__traits(compiles, { immutable(B)[] b = dsc; }));
3655
3656 static assert(!__traits(compiles, { B [] b = dsw; }));
3657 static assert(!__traits(compiles, { const(B)[] b = dsw; }));
3658 static assert(!__traits(compiles, { inout(B)[] b = dsw; }));
3659 static assert(!__traits(compiles, { shared(B)[] b = dsw; }));
3660 static assert( __traits(compiles, { shared(const B)[] b = dsw; }));
3661 static assert(!__traits(compiles, { shared(inout B)[] b = dsw; }));
3662 static assert(!__traits(compiles, { immutable(B)[] b = dsw; }));
3663
3664 static assert(!__traits(compiles, { B [] b = di; }));
3665 static assert( __traits(compiles, { const(B)[] b = di; }));
3666 static assert(!__traits(compiles, { inout(B)[] b = di; }));
3667 static assert(!__traits(compiles, { shared(B)[] b = di; }));
3668 static assert( __traits(compiles, { shared(const B)[] b = di; }));
3669 static assert(!__traits(compiles, { shared(inout B)[] b = di; }));
3670 static assert( __traits(compiles, { immutable(B)[] b = di; }));
3671 }
3672
3673 /************************************/
3674 // 11768
3675
3676 void test11768(inout int = 0)
3677 {
3678 const(inout(char)) k1;
3679 inout(const(char)) k2;
3680 static assert(typeof(k1).stringof == "inout(const(char))"); // OK
3681 static assert(typeof(k2).stringof == "inout(const(char))"); // fails
3682 static assert(is(typeof(k1) == typeof(k2))); // fails
3683 }
3684
3685 /************************************/
3686 // 12403
3687
3688 void test12403()
3689 {
3690 void func(K, V)(inout(V[K]) aa)
3691 {
3692 static assert(is(V == const int));
3693 static assert(is(K == int));
3694 }
3695
3696 const(int)[int] m;
3697 func(m);
3698 }
3699
3700 /************************************/
3701 // 13011
3702
3703 void test13011()
3704 {
3705 static size_t hashOf(int delegate() inout val)
3706 {
3707 return 0;
3708 }
3709
3710 int delegate() inout dg;
3711 auto h = hashOf(dg);
3712 }
3713
3714 /************************************/
3715 // 13030
3716
3717 void va13030(Args...)(const Args args) {}
3718
3719 void func13030(int delegate(int n) a)
3720 {
3721 va13030(a);
3722 }
3723
3724 /************************************/
3725 // 13802 & 13803
3726
3727 static assert(( string ).stringof == "string" );
3728 static assert(( string[] ).stringof == "string[]" );
3729 static assert(( string[1] ).stringof == "string[1]" );
3730 static assert(( string[int]).stringof == "string[int]" );
3731 static assert(( const string ).stringof == "const(string)" );
3732 static assert(( const string[] ).stringof == "const(string[])" );
3733 static assert(( const string[1] ).stringof == "const(string[1])" );
3734 static assert(( const string[int]).stringof == "const(string[int])" );
3735 static assert((shared string ).stringof == "shared(string)" );
3736 static assert((shared string[] ).stringof == "shared(string[])" );
3737 static assert((shared string[1] ).stringof == "shared(string[1])" );
3738 static assert((shared string[int]).stringof == "shared(string[int])" );
3739 static assert((shared const string ).stringof == "shared(const(string))" );
3740 static assert((shared const string[] ).stringof == "shared(const(string[]))" );
3741 static assert((shared const string[1] ).stringof == "shared(const(string[1]))" );
3742 static assert((shared const string[int]).stringof == "shared(const(string[int]))");
3743 static assert(( immutable string ).stringof == "immutable(string)" );
3744 static assert(( immutable string[] ).stringof == "immutable(string[])" );
3745 static assert(( immutable string[1] ).stringof == "immutable(string[1])" );
3746 static assert(( immutable string[int]).stringof == "immutable(string[int])" );
3747
3748 static assert(( wstring ).stringof == "wstring" );
3749 static assert(( wstring[] ).stringof == "wstring[]" );
3750 static assert(( wstring[1] ).stringof == "wstring[1]" );
3751 static assert(( wstring[int]).stringof == "wstring[int]" );
3752 static assert(( const wstring ).stringof == "const(wstring)" );
3753 static assert(( const wstring[] ).stringof == "const(wstring[])" );
3754 static assert(( const wstring[1] ).stringof == "const(wstring[1])" );
3755 static assert(( const wstring[int]).stringof == "const(wstring[int])" );
3756 static assert((shared wstring ).stringof == "shared(wstring)" );
3757 static assert((shared wstring[] ).stringof == "shared(wstring[])" );
3758 static assert((shared wstring[1] ).stringof == "shared(wstring[1])" );
3759 static assert((shared wstring[int]).stringof == "shared(wstring[int])" );
3760 static assert((shared const wstring ).stringof == "shared(const(wstring))" );
3761 static assert((shared const wstring[] ).stringof == "shared(const(wstring[]))" );
3762 static assert((shared const wstring[1] ).stringof == "shared(const(wstring[1]))" );
3763 static assert((shared const wstring[int]).stringof == "shared(const(wstring[int]))");
3764 static assert(( immutable wstring ).stringof == "immutable(wstring)" );
3765 static assert(( immutable wstring[] ).stringof == "immutable(wstring[])" );
3766 static assert(( immutable wstring[1] ).stringof == "immutable(wstring[1])" );
3767 static assert(( immutable wstring[int]).stringof == "immutable(wstring[int])" );
3768
3769 static assert(( dstring ).stringof == "dstring" );
3770 static assert(( dstring[] ).stringof == "dstring[]" );
3771 static assert(( dstring[1] ).stringof == "dstring[1]" );
3772 static assert(( dstring[int]).stringof == "dstring[int]" );
3773 static assert(( const dstring ).stringof == "const(dstring)" );
3774 static assert(( const dstring[] ).stringof == "const(dstring[])" );
3775 static assert(( const dstring[1] ).stringof == "const(dstring[1])" );
3776 static assert(( const dstring[int]).stringof == "const(dstring[int])" );
3777 static assert((shared dstring ).stringof == "shared(dstring)" );
3778 static assert((shared dstring[] ).stringof == "shared(dstring[])" );
3779 static assert((shared dstring[1] ).stringof == "shared(dstring[1])" );
3780 static assert((shared dstring[int]).stringof == "shared(dstring[int])" );
3781 static assert((shared const dstring ).stringof == "shared(const(dstring))" );
3782 static assert((shared const dstring[] ).stringof == "shared(const(dstring[]))" );
3783 static assert((shared const dstring[1] ).stringof == "shared(const(dstring[1]))" );
3784 static assert((shared const dstring[int]).stringof == "shared(const(dstring[int]))");
3785 static assert(( immutable dstring ).stringof == "immutable(dstring)" );
3786 static assert(( immutable dstring[] ).stringof == "immutable(dstring[])" );
3787 static assert(( immutable dstring[1] ).stringof == "immutable(dstring[1])" );
3788 static assert(( immutable dstring[int]).stringof == "immutable(dstring[int])" );
3789
3790 /************************************/
3791
3792 int main()
3793 {
3794 test1();
3795 test2();
3796 test3();
3797 test4();
3798 test5();
3799 test6();
3800 test8();
3801 test9();
3802 test10();
3803 test11();
3804 test12();
3805 test13();
3806 test14();
3807 test15();
3808 test16();
3809 test17();
3810 test18();
3811 test19();
3812 test20();
3813 test21();
3814 test22();
3815 test23();
3816 test24();
3817 test25();
3818 test26();
3819 test27();
3820 test28();
3821 test29();
3822 test30();
3823 test31();
3824 test32();
3825 test33();
3826 test34();
3827 test35();
3828 test36();
3829 test37();
3830 test38();
3831 test39();
3832 test40();
3833 test41();
3834 test42();
3835 test43();
3836 test44();
3837 test45();
3838 test46();
3839 test47();
3840 test48();
3841 test49();
3842 test50();
3843 test51();
3844 test52();
3845 test53();
3846 test54();
3847 test55();
3848 test56();
3849 test57();
3850 test58();
3851 test59();
3852 test60();
3853 test61();
3854 test62();
3855 test63();
3856 test64();
3857 test65();
3858 test66();
3859 test68();
3860 test69();
3861 test70();
3862 test72();
3863 test73();
3864 test74();
3865 test75();
3866 test76();
3867 test77();
3868 test78();
3869 test79();
3870 test80();
3871 test81();
3872 test82();
3873 test83();
3874 test84();
3875 test85();
3876 test87();
3877 test4968();
3878 test3748();
3879 test1961a();
3880 test1961b();
3881 test1961c();
3882 test88();
3883 test4251a();
3884 test4251b();
3885 test5473();
3886 test5493();
3887 test5493inout();
3888 test6782();
3889 test6864();
3890 test6865();
3891 test6866();
3892 test6870();
3893 test6912();
3894 test6930a();
3895 test6930b();
3896 test11868();
3897 test6939();
3898 test6940();
3899 test6982();
3900 test7038();
3901 test7105();
3902 test7202();
3903 test7554();
3904 test7518();
3905 test7669();
3906 test7757();
3907 test8098();
3908 test8099();
3909 test8201();
3910 test8212();
3911 test8366();
3912 test8408();
3913 test8688();
3914 test9046();
3915 test9090();
3916 test9461();
3917 test9209();
3918 test11226();
3919 test11768();
3920 test13011();
3921
3922 printf("Success\n");
3923 return 0;
3924 }
3925