1 // PERMUTE_ARGS:
2 
3 /**************************************************
4     1748 class template with stringof
5 **************************************************/
6 
S1748(T)7 struct S1748(T) {}
8 static assert(S1748!int.stringof == "S1748!int");
9 
C1748(T)10 class C1748(T) {}
11 static assert(C1748!int.stringof == "C1748!int");
12 
13 /**************************************************
14     2354 pragma + single semicolon DeclarationBlock
15 **************************************************/
16 
17 version(all)
18     pragma(inline, true);
19 else
20     pragma(inline, false);
21 
22 /**************************************************
23     2438
24 **************************************************/
25 
26 alias void delegate() Dg2438;
27 
28 alias typeof(Dg2438.ptr)     CP2438a;
29 alias typeof(Dg2438.funcptr) FP2438a;
30 static assert(is(CP2438a == void*));
31 static assert(is(FP2438a == void function()));
32 
33 alias typeof(Dg2438.init.ptr)     CP2438b;
34 alias typeof(Dg2438.init.funcptr) FP2438b;
35 static assert(is(CP2438b == void*));
36 static assert(is(FP2438b == void function()));
37 
38 /**************************************************
39     4225
40 **************************************************/
41 
42 struct Foo4225
43 {
44     enum x = Foo4225();
45 
opCallFoo422546     static Foo4225 opCall()
47     {
48         return Foo4225.init;
49     }
50 }
51 
52 /**************************************************
53     5996    ICE(expression.c)
54 **************************************************/
55 
T5996(T)56 template T5996(T)
57 {
58     auto bug5996() {
59         if (anyOldGarbage) {}
60         return 2;
61     }
62 }
63 static assert(!is(typeof(T5996!(int).bug5996())));
64 
65 /**************************************************
66     8532    segfault(mtype.c) - type inference + pure
67 **************************************************/
segfault8532(Y,R...)68 auto segfault8532(Y, R ...)(R r, Y val) pure
69 { return segfault8532(r, val); }
70 
71 static assert(!is(typeof( segfault8532(1,2,3))));
72 
73 /**************************************************
74     8982    ICE(ctfeexpr.c) __parameters with error in default value
75 **************************************************/
ice8982(T)76 template ice8982(T)
77 {
78     void bug8982(ref const int v = 7){}
79 
80     static if (is(typeof(bug8982) P == __parameters)) {
81         enum eval8982 = ((P[0..1] g) => g[0])();
82     }
83 }
84 
85 static assert(!is(ice8982!(int)));
86 
87 
88 /**************************************************
89     8801    ICE assigning to __ctfe
90 **************************************************/
91 static assert(!is(typeof( { bool __ctfe= true; })));
92 static assert(!is(typeof( { __ctfe |= true; })));
93 
94 /**************************************************
95     5932    ICE(s2ir.c)
96     6675    ICE(glue.c)
97 **************************************************/
98 
bug3932(T)99 void bug3932(T)() {
100     static assert( 0 );
101     func5932( 7 );
102 }
103 
func5932(T)104 void func5932(T)( T val ) {
105     void onStandardMsg() {
106         foreach( t; T ) { }
107     }
108 }
109 
110 static assert(!is(typeof(
111     {
112         bug3932!(int)();
113     }()
114 )));
115 
116 /**************************************************
117     6650    ICE(glue.c) or wrong-code
118 **************************************************/
119 
bug6650(X)120 auto bug6650(X)(X y)
121 {
122     X q;
123     q = "abc";
124     return y;
125 }
126 
127 static assert(!is(typeof(bug6650!(int)(6))));
128 static assert(!is(typeof(bug6650!(int)(18))));
129 
130 /**************************************************
131     14710    VC-built DMD crashes on templated variadic function IFTI
132 **************************************************/
133 
bug14710a(T)134 void bug14710a(T)(T val, T[] arr...)
135 {
136 }
137 
bug14710b()138 void bug14710b()
139 {
140     bug14710a("", "");
141 }
142 
143 /**************************************************
144   6661 Templates instantiated only through is(typeof()) shouldn't cause errors
145 **************************************************/
146 
bug6661(Q)147 template bug6661(Q)
148 {
149     int qutz(Q y)
150     {
151         Q q = "abc";
152         return 67;
153     }
154     static assert(qutz(13).sizeof!=299);
155     const Q blaz = 6;
156 }
157 
158 static assert(!is(typeof(bug6661!(int).blaz)));
159 
bug6661x(Q)160 template bug6661x(Q)
161 {
162     int qutz(Q y)
163     {
164         Q q = "abc";
165         return 67;
166     }
167 }
168 // should pass, but doesn't in current
169 //static assert(!is(typeof(bug6661x!(int))));
170 
171 /**************************************************
172     6599    ICE(constfold.c) or segfault
173 **************************************************/
174 
bug6599extraTest(string x)175 string bug6599extraTest(string x) { return x ~ "abc"; }
176 
Bug6599(X)177 template Bug6599(X)
178 {
179     class Orbit
180     {
181         Repository repository = Repository();
182     }
183 
184     struct Repository
185     {
186         string fileProtocol = "file://";
187         string blah = bug6599extraTest("abc");
188         string source = fileProtocol ~ "/usr/local/orbit/repository";
189     }
190 }
191 
192 static assert(!is(typeof(Bug6599!int)));
193 
194 /**************************************************
195     8422    TypeTuple of tuples can't be read at compile time
196 **************************************************/
197 
198 template TypeTuple8422(TList...)
199 {
200     alias TList TypeTuple8422;
201 }
202 
203 struct S8422 { int x; }
204 
205 void test8422()
206 {
207     enum a = S8422(1);
208     enum b = S8422(2);
209     enum c = [1,2,3];
210     foreach(t; TypeTuple8422!(b, a)) {
211         enum u = t;
212     }
213     foreach(t; TypeTuple8422!(c)) {
214         enum v = t;
215     }
216 }
217 
218 /**************************************************
219     6096    ICE(el.c) with -O
220 **************************************************/
221 
222 cdouble c6096;
223 
224 int bug6096()
225 {
226     if (c6096) return 0;
227     return 1;
228 }
229 
230 /**************************************************
231     7681  Segfault
232 **************************************************/
233 
234 static assert( !is(typeof( (){
235       undefined ~= delegate(){}; return 7;
236   }())));
237 
238 /**************************************************
239     8639  Buffer overflow
240 **************************************************/
241 
242 void t8639(alias a)() {}
243 void bug8639() {
244   t8639!({auto r = -real.max;})();
245 }
246 
247 /**************************************************
248     7751  Segfault
249 **************************************************/
250 
251 static assert( !is(typeof( (){
252     bar[]r; r ~= [];
253      return 7;
254   }())));
255 
256 /**************************************************
257     7639  Segfault
258 **************************************************/
259 
260 static assert( !is(typeof( (){
261     enum foo =
262     [
263         str : "functions",
264     ];
265 })));
266 
267 /**************************************************
268     11991
269 **************************************************/
270 
271 void main()
272 {
273     int Throwable;
274     int object;
275     try
276     {
277     }
278     catch(.object.Throwable)
279     {
280     }
281 }
282 
283 /**************************************************
284     11939
285 **************************************************/
286 
287 void test11939()
288 {
289     scope(failure)
290     {
291         import object : Object;
292     }
293     throw new Exception("");
294 }
295 
296 /**************************************************
297     5796
298 **************************************************/
299 
300 template A(B) {
301     pragma(lib, "missing ;")
302     enum X = 0;
303 }
304 
305 static assert(!is(typeof(A!(int))));
306 
307 /**************************************************
308     6720
309 **************************************************/
310 void bug6720() { }
311 
312 static assert(!is(typeof(
313 cast(bool)bug6720()
314 )));
315 
316 /**************************************************
317     1099
318 **************************************************/
319 
320 template Mix1099(int a) {
321    alias typeof(this) ThisType;
322     static assert (ThisType.init.tupleof.length == 2);
323 }
324 
325 
326 struct Foo1099 {
327     mixin Mix1099!(0);
328     int foo;
329     mixin Mix1099!(1);
330     int bar;
331     mixin Mix1099!(2);
332 }
333 
334 /**************************************************
335     8788 - super() and return
336 **************************************************/
337 
338 class B8788 {
339         this ( ) { }
340 }
341 
342 class C8788(int test) : B8788
343 {
344     this ( int y )
345     {   // TESTS WHICH SHOULD PASS
346         static if (test == 1) {
347             if (y == 3) {
348                 super();
349                 return;
350             }
351             super();
352             return;
353         } else static if (test == 2) {
354             if (y == 3) {
355                 super();
356                 return;
357             }
358             super();
359         } else static if (test == 3) {
360             if (y > 3) {
361                 if (y == 7) {
362                    super();
363                    return;
364                 }
365                 super();
366                 return;
367             }
368             super();
369         } else static if (test == 4) {
370             if (y > 3) {
371                 if (y == 7) {
372                    super();
373                    return;
374                 }
375                 else if (y> 5)
376                     super();
377                 else super();
378                 return;
379             }
380             super();
381         }
382         // TESTS WHICH SHOULD FAIL
383         else static if (test == 5) {
384             if (y == 3) {
385                 super();
386                 return;
387             }
388             return; // no super
389         } else static if (test == 6) {
390             if (y > 3) {
391                 if (y == 7) {
392                    super();
393                    return;
394                 }
395                 super();
396             }
397             super(); // two calls
398         } else static if (test == 7) {
399             if (y == 3) {
400                 return; // no super
401             }
402             super();
403         } else static if (test == 8) {
404             if (y > 3) {
405                 if (y == 7) {
406                    return; // no super
407                 }
408                 super();
409                 return;
410             }
411             super();
412         } else static if (test == 9) {
413             if (y > 3) {
414                 if (y == 7) {
415                    super();
416                    return;
417                 }
418                 else if (y> 5)
419                     super();
420                 else return; // no super
421                 return;
422             }
423             super();
424         }
425     }
426 }
427 
428 static assert( is(typeof( { new C8788!(1)(0); } )));
429 static assert( is(typeof( { new C8788!(2)(0); } )));
430 static assert( is(typeof( { new C8788!(3)(0); } )));
431 static assert( is(typeof( { new C8788!(4)(0); } )));
432 static assert(!is(typeof( { new C8788!(5)(0); } )));
433 static assert(!is(typeof( { new C8788!(6)(0); } )));
434 static assert(!is(typeof( { new C8788!(7)(0); } )));
435 static assert(!is(typeof( { new C8788!(8)(0); } )));
436 static assert(!is(typeof( { new C8788!(9)(0); } )));
437 
438 /**************************************************
439     4967, 7058
440 **************************************************/
441 
442 enum Bug7058 bug7058 = { 1.5f, 2};
443 static assert(bug7058.z == 99);
444 
445 struct Bug7058
446 {
447      float x = 0;
448      float y = 0;
449      float z = 99;
450 }
451 
452 
453 /***************************************************/
454 
455 void test12094()
456 {
457     auto n = null;
458     int *a;
459     int[int] b;
460     int[] c;
461     auto u = true ? null : a;
462     auto v = true ? null : b;
463     auto w = true ? null : c;
464     auto x = true ? n : a;
465     auto y = true ? n : b;
466     auto z = true ? n : c;
467     a = n;
468     b = n;
469     c = n;
470 }
471 
472 /***************************************************/
473 
474 template test8163(T...)
475 {
476     struct Point
477     {
478         T fields;
479     }
480 
481     enum N = 2; // N>=2 triggers the bug
482     extern Point[N] bar();
483 
484     void foo()
485     {
486         Point[N] _ = bar();
487     }
488 }
489 
490 alias test8163!(long) _l;
491 alias test8163!(double) _d;
492 alias test8163!(float, float) _ff;
493 alias test8163!(int, int) _ii;
494 alias test8163!(int, float) _if;
495 alias test8163!(ushort, ushort, ushort, ushort) _SSSS;
496 alias test8163!(ubyte, ubyte, ubyte, ubyte, ubyte, ubyte, ubyte, ubyte) _BBBBBBBB;
497 alias test8163!(ubyte, ubyte, ushort, float) _BBSf;
498 
499 
500 /***************************************************/
501 // 4757
502 
503 auto foo4757(T)(T)
504 {
505     static struct Bar(T)
506     {
507         void spam()
508         {
509             foo4757(1);
510         }
511     }
512     return Bar!T();
513 }
514 
515 void test4757()
516 {
517     foo4757(1);
518 }
519 
520 /***************************************************/
521 // 9348
522 
523 void test9348()
524 {
525     @property Object F(int E)() { return null; }
526 
527     assert(F!0 !is null);
528     assert(F!0 !in [new Object():1]);
529 }
530 
531 /***************************************************/
532 // 9690
533 
534 @disable
535 {
536     void dep9690() {}
537     void test9690()
538     {
539         dep9690();      // OK
540         void inner()
541         {
542             dep9690();  // OK <- NG
543         }
544     }
545 }
546 
547 /***************************************************/
548 // 9987
549 
550 static if (is(object.ModuleInfo == struct))
551 {
552     struct ModuleInfo {}
553 
554     static assert(!is(object.ModuleInfo == ModuleInfo));
555     static assert(object.ModuleInfo.sizeof != ModuleInfo.sizeof);
556 }
557 static if (is(object.ModuleInfo == class))
558 {
559     class ModuleInfo {}
560 
561     static assert(!is(object.ModuleInfo == ModuleInfo));
562     static assert(__traits(classInstanceSize, object.ModuleInfo) !=
563                   __traits(classInstanceSize, ModuleInfo));
564 }
565 
566 /***************************************************/
567 // 10158
568 
569 class Outer10158
570 {
571     static struct Inner
572     {
573         int f;
574     }
575 
576     void test()
577     {
578         static assert( Inner.f .offsetof == 0);  // OK <- NG
579         static assert((Inner.f).offsetof == 0);  // OK
580     }
581 }
582 
583 void test10158()
584 {
585     static assert(Outer10158.Inner.f.offsetof == 0);  // OK
586 }
587 
588 /***************************************************/
589 // 10326
590 
591 class C10326
592 {
593     int val;
594     invariant   { assert(val == 0); }
595     invariant() { assert(val == 0); }
596 }
597 
598 /***************************************************/
599 // 11042
600 
601 static if           ((true  || error) == true ) {} else { static assert(0); }
602 static if           ((false && error) == false) {} else { static assert(0); }
603 static assert       ((true  || error) == true );
604 static assert       ((false && error) == false);
605 int f11042a1()() if ((true  || error) == true ) { return 0; }   enum x11042a1 = f11042a1();
606 int f11042b1()() if ((false && error) == false) { return 0; }   enum x11042b1 = f11042b1();
607 
608 static if           (is(typeof(true  || error)) == false) {} else { static assert(0); }
609 static if           (is(typeof(false && error)) == false) {} else { static assert(0); }
610 static assert       (is(typeof(true  || error)) == false);
611 static assert       (is(typeof(false && error)) == false);
612 int f11042a2()() if (is(typeof(true  || error)) == false) { return 0; }   enum x11042a2 = f11042a2();
613 int f11042b2()() if (is(typeof(false && error)) == false) { return 0; }   enum x11042b2 = f11042b2();
614 
615 static if           (__traits(compiles, true  || error) == false) {} else { static assert(0); }
616 static if           (__traits(compiles, false && error) == false) {} else { static assert(0); }
617 static assert       (__traits(compiles, true  || error) == false);
618 static assert       (__traits(compiles, false && error) == false);
619 int f11042a3()() if (__traits(compiles, true  || error) == false) { return 0; }   enum x11042a3 = f11042a3();
620 int f11042b3()() if (__traits(compiles, false && error) == false) { return 0; }   enum x11042b3 = f11042b3();
621 
622 /***************************************************/
623 // 11554
624 
625 enum E11554;
626 static assert(is(E11554 == enum));
627 
628 struct Bro11554(N...) {}
629 static assert(!is(E11554 unused : Bro11554!M, M...));
630 
631 /***************************************************/
632 // 12302
633 
634 template isCallable12302(T...)
635     if (T.length == 1)
636 {
637     static if (is(typeof(& T[0].opCall) == delegate))
638         enum bool isCallable12302 = true;
639     else
640     static if (is(typeof(& T[0].opCall) V : V*) && is(V == function))
641         enum bool isCallable12302 = true;
642     else
643         enum bool isCallable12302 = true;
644 }
645 
646 class A12302
647 {
648     struct X {}
649     X x;
650     auto opDispatch(string s, TArgs...)(TArgs args)
651     {
652         mixin("return x."~s~"(args);");
653     }
654 }
655 
656 A12302 func12302() { return null; }
657 enum b12302 = isCallable12302!func12302;
658 
659 /***************************************************/
660 // 12476
661 
662 template A12476(T) {  }
663 
664 struct S12476(T)
665 {
666     alias B = A12476!T;
667 }
668 
669 class C12476(T)
670 {
671     alias B = A12476!T;
672 }
673 
674 struct Bar12476(alias Foo)
675 {
676     Foo!int baz;
677     alias baz this;
678 }
679 
680 alias Identity12476(alias A) = A;
681 
682 alias sb12476 = Identity12476!(Bar12476!S12476.B);
683 alias cb12476 = Identity12476!(Bar12476!C12476.B);
684 
685 static assert(__traits(isSame, sb12476, A12476!int));
686 static assert(__traits(isSame, cb12476, A12476!int));
687 
688 /***************************************************/
689 // 12506
690 
691 import imports.a12506;
692 private           bool[9] r12506a = f12506!(i => true)(); // OK
693 private immutable bool[9] r12506b = f12506!(i => true)(); // OK <- error
694 
695 /***************************************************/
696 // 12555
697 
698 class A12555(T)
699 {
700     Undef12555 error;
701 }
702 
703 static assert(!__traits(compiles, {
704     class C : A12555!C  { }
705 }));
706 
707 /***************************************************/
708 // 11622
709 
710 class A11622(T)
711 {
712     B11622!T foo()
713     {
714         return new B11622!T;
715     }
716 }
717 
718 class B11622(T) : T
719 {
720 }
721 
722 static assert(!__traits(compiles, {
723     class C : A11622!C  { }
724 }));
725 
726 /***************************************************/
727 // 12688
728 
729 void writeln12688(A...)(A) {}
730 
731 struct S12688
732 {
733     int foo() @property { return 1; }
734 }
735 
736 void test12688()
737 {
738     S12688 s;
739     s.foo.writeln12688;   // ok
740     (s.foo).writeln12688; // ok <- ng
741 }
742 
743 /***************************************************/
744 // 12703
745 
746 struct S12703
747 {
748     this(int) {}
749 }
750 
751 final class C12703
752 {
753     S12703 s = S12703(1);
754 }
755 
756 /***************************************************/
757 // 12799
758 
759 struct A12799
760 {
761     int a;
762     enum C = A12799.sizeof;
763     enum D = C; // OK <- Error
764 }
765 
766 /***************************************************/
767 // 13236
768 
769 enum bug13286 = is(typeof({ struct S { S x; } }));
770 
771 /***************************************************/
772 // 13280
773 
774 struct S13280
775 {
776     alias U = ubyte;
777     alias T1 =       ubyte[this.sizeof]; // ok
778     alias T2 = const     U[this.sizeof]; // ok
779     alias T3 = const ubyte[this.sizeof]; // ok <- error
780 }
781 
782 /***************************************************/
783 // 13481
784 
785 mixin template Mix13481(void function() callback)
786 {
787     static this()
788     {
789         callback();
790     }
791 }
792 
793 /***************************************************/
794 // 13564
795 
796 class E13564(T)
797 {
798     int pos;
799 }
800 
801 class C13564(T)
802 {
803     struct S
804     {
805         ~this()
806         {
807             C13564!int c;
808             c.element.pos = 0;
809         }
810     }
811 
812     E13564!T element;
813 }
814 
815 void test13564()
816 {
817     auto c = new C13564!int();
818 }
819 
820 /***************************************************/
821 // 14166
822 
823 struct Proxy14166(T)
824 {
825     T* ptr;
826     ref deref() { return *ptr; }
827     alias deref this;
828 }
829 struct Test14166
830 {
831     auto opIndex() { return this; }
832     auto opIndex(int) { return 1; }
833 }
834 template Elem14166a(R) { alias Elem14166a = typeof(R.init[][0]); }
835 template Elem14166b(R) { alias Elem14166b = typeof(R.init[0]); }
836 void test14166()
837 {
838     alias T = Proxy14166!Test14166;
839     static assert(is(Elem14166a!T == int));     // rejects-valid case
840     static assert(is(Elem14166b!T == int));     // regression case
841 }
842 
843 // other related cases
844 struct S14166
845 {
846     int x;
847     double y;
848     int[] a;
849     S14166 opUnary(string op : "++")() { return this;  }
850 }
851 S14166 s14166;
852 
853 struct X14166 { this(int) { } X14166 opAssign(int) { return this; } }
854 X14166[int] aa14166;
855 X14166[int] makeAA14166() { return aa14166; }
856 
857 struct Tup14166(T...) { T field; alias field this; }
858 Tup14166!(int, int) tup14166;
859 Tup14166!(int, int) makeTup14166() { return tup14166; }
860 alias TT14166(T...) = T;
861 
862 static assert(is(typeof((s14166.x += 1) = 2) == int));     // ok <- error
863 static assert(is(typeof(s14166.a.length += 2) == size_t)); // ok <- error
864 static assert(is(typeof(s14166++) == S14166));             // ok <- error
865 static assert(is(typeof(s14166.x ^^ 2) == int));           // ok <- error
866 static assert(is(typeof(s14166.y ^^= 2.5) == double));     // ok <- error
867 static assert(is(typeof(makeAA14166()[0] = 1) == X14166)); // ok <- error
868 static assert(is(typeof(tup14166.field = makeTup14166()) == TT14166!(int, int))); // ok <- error
869 
870 /***************************************************/
871 // 14388
872 
873 @property immutable(T)[] idup14388(T)(T[] a)
874 {
875     alias U = immutable(T);
876     U[] res;
877     foreach (ref e; a)
878         res ~= e;
879     return res;
880 }
881 
882 struct Data14388(A14388 a)
883 {
884     auto foo()
885     {
886         return Data14388!a.init;    // [B]
887     }
888 }
889 
890 struct A14388
891 {
892     struct Item {}
893 
894     immutable(Item)[] items;
895 
896     this(int dummy)
897     {
898         items = [Item()].idup14388;
899     }
900 }
901 
902 void test14388()
903 {
904     auto test = Data14388!(A14388(42)).init.foo();  // [A]
905     /*
906      * A(42) is interpreter to a struct literal A([immutable(Item)()]).
907      * The internal VarDeclaration with STCmanifest for the Data's template parameteter 'a'
908      * calls syntaxCopy() on its ((ExpInitializer *)init)->exp in VarDeclaration::semantic(),
909      * and 'immutable(Item)()'->syntaxCopy() had incorrectly removed the qualifier.
910      * Then, the arguments of two Data template instances at [A] and [B] had become unmatch,
911      * and the second instantiation had created the AST duplication.
912      */
913 }
914 
915 /***************************************************/
916 // 15163
917 
918 void function() func15164(int[] arr)
919 {
920     return () { };
921 }
922 
923 void test15163()
924 {
925     auto arr = [[0]];
926     func15164(arr[0])();
927 }
928 
929 /**************************************************
930     3438
931 **************************************************/
932 import core.vararg;
933 struct S3438_1 { this(int x, int y = 1) { } }
934 struct S3438_2 { this(int x, ...) { } }
935 struct S3438_3 { this(int x, int[] arr...) { } }
936 struct S3438_4 { this(...) { } }
937 struct S3438_5 { this(int[] arr...) { } }
938 
939 /***************************************************/
940 // 15362
941 
942 void func15362()
943 {
944     assert(true);
945     assert(true,);
946     assert(true, "So true");
947     assert(true, "Very, very true",);
948     static assert(true);
949     static assert(true,);
950     static assert(true, "So true");
951     static assert(true, "Very, very true",);
952 }
953 
954 /***************************************************/
955 // 15799
956 
957 interface I15799
958 {
959     void funA();
960 
961     void funB(int n)
962     in {
963         assert(n);
964     }; // Semicolon is not a part of function declaration. It's an empty declaration.
965 }
966