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