1 extern(C) int printf(const char*, ...);
2 
3 alias TypeTuple(T...) = T;
4 
5 /***************************************************/
6 // 13336
7 
8 struct S13336
9 {
opApplyS1333610     int opApply(scope int delegate(int) dg)
11     {
12         return dg(0);
13     }
14 }
15 
16 double result13336;
17 
18 enum fbody13336 =
19 q{
20     static if (n == 1)
21     {
22         if (f)
23             return sx;
24         return sy;
25     }
26     static if (n == 2)
27     {
28         foreach (e; S13336())
29         {
30             if (f)
31                 return sx;
32             return sy;
33         }
34         assert(0);
35     }
36     static if (n == 3)
37     {
38         if (f)
39             return sx;
40         foreach (e; S13336())
41         {
42             return sy;
43         }
44         assert(0);
45     }
46     static if (n == 4)
47     {
48         foreach (e; S13336())
49         {
50             if (f)
51                 return sx;
52         }
53         return sy;
54     }
55     static if (n == 5)
56     {
57         if (false)
58             return 99;
59         foreach (e; S13336())
60         {
61             if (f)
62                 return sx;
63             return sy;
64         }
65         assert(0);
66     }
67     static if (n == 6)
68     {
69         foreach (e; S13336())
70         {
71             if (f)
72                 return sx;
73             return sy;
74         }
75         return 99;
76     }
77 };
78 
79 // auto ref without out contract
f13336a(int n,alias sx,alias sy)80 auto ref f13336a(int n, alias sx, alias sy)(bool f)
81 {
82     mixin(fbody13336);
83 }
84 
85 // auto without out contract
f13336b(int n,alias sx,alias sy)86 auto f13336b(int n, alias sx, alias sy)(bool f)
87 {
88     mixin(fbody13336);
89 }
90 
91 // auto ref with out contract
f13336c(int n,alias sx,alias sy)92 auto ref f13336c(int n, alias sx, alias sy)(bool f)
93 out(r)
94 {
95     static assert(is(typeof(r) == const double));
96     assert(r == (f ? sx : sy));
97     result13336 = r;
98 }
99 body
100 {
101     mixin(fbody13336);
102 }
103 
104 // auto with out contract
f13336d(int n,alias sx,alias sy)105 auto f13336d(int n, alias sx, alias sy)(bool f)
106 out(r)
107 {
108     static assert(is(typeof(r) == const double));
109     assert(r == (f ? sx : sy));
110     result13336 = r;
111 }
112 body
113 {
114     mixin(fbody13336);
115 }
116 
test13336()117 void test13336()
118 {
119     static int sx = 1;
120     static double sy = 2.5;
121 
122     foreach (num; TypeTuple!(1, 2, 3, 4, 5, 6))
123     {
124         foreach (foo; TypeTuple!(f13336a, f13336b))
125         {
126             alias fooxy = foo!(num, sx, sy);
127             static assert(is(typeof(&fooxy) : double function(bool)));
128             assert(fooxy(1) == 1.0);
129             assert(fooxy(0) == 2.5);
130 
131             alias fooyx = foo!(num, sy, sx);
132             static assert(is(typeof(&fooyx) : double function(bool)));
133             assert(fooyx(1) == 2.5);
134             assert(fooyx(0) == 1.0);
135         }
136 
137         foreach (foo; TypeTuple!(f13336c, f13336d))
138         {
139             alias fooxy = foo!(num, sx, sy);
140             static assert(is(typeof(&fooxy) : double function(bool)));
141             assert(fooxy(1) == 1.0 && result13336 == 1.0);
142             assert(fooxy(0) == 2.5 && result13336 == 2.5);
143 
144             alias fooyx = foo!(num, sy, sx);
145             static assert(is(typeof(&fooyx) : double function(bool)));
146             assert(fooyx(1) == 2.5 && result13336 == 2.5);
147             assert(fooyx(0) == 1.0 && result13336 == 1.0);
148         }
149     }
150 }
151 
152 /***************************************************/
153 // 15018
154 
S15018(int n)155 struct S15018(int n)
156 {
157     short[n] m;
158 }
159 
160 S15018!n f15018(int n)()
161 {
162     S15018!n s;
163     foreach(i; 0..n)
164         s.m[i] = cast(short)(i * i + 3);
165     return s;
166 }
167 
test15018()168 void test15018()
169 {
170     // size 4
171     S15018!2[3] s3;
172     s3[] = f15018!2();
173     foreach (int i; 0..3)
174     {
175         assert(s3[i].m[0] == 3);
176         assert(s3[i].m[1] == 4);
177     }
178 
179     // size 4-18
180     foreach (n; TypeTuple!(2, 3, 4, 5, 6, 7, 8, 9))
181     {
182         S15018!n[5] i5;
183         i5[] = f15018!n();
184         foreach (int j; 0..5)
185             foreach(k; 0..n)
186                 if (i5[j].m[k] != k * k + 3)
187                     assert(false);
188     }
189 }
190 
191 /***************************************************/
192 
main()193 int main()
194 {
195     test13336();
196     test15018();
197 
198     printf("Success\n");
199     return 0;
200 }
201