Debian Codegraph @

gcc/testsuite/gdc.test/runnable/testconst.d

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