1 
2 //import std.stdio;
3 extern(C) int printf(const char*, ...);
4 
Tuple(A...)5 template Tuple(A...)
6 {
7     alias A Tuple;
8 }
9 
eval(A...)10 template eval(A...)
11 {
12     const typeof(A[0]) eval = A[0];
13 }
14 
15 /************************************************/
16 
foo1()17 int foo1()
18 {
19     int x;
20     foreach (i; 0 .. 10)
21         x += i;
22     return x;
23 }
24 
bar1()25 int bar1()
26 {
27     int x;
28     foreach_reverse (i; 0 .. 10)
29     {
30         x <<= 1;
31         x += i;
32     }
33     return x;
34 }
35 
test1()36 void test1()
37 {
38     const y = foo1();
39     //writeln(y);
40     assert(y == 45);
41 
42     auto y1 = foo1();
43     //writeln(y1);
44     assert(y1 == 45);
45 
46     const z = bar1();
47     //writeln(z);
48     assert(z == 8194);
49 
50     auto z1 = bar1();
51     //writeln(z1);
52     assert(z1 == 8194);
53 }
54 
55 /***** Bug 2850 *********************************/
56 
57 /* These tests are not passing, and shouldn't pass. A non-first field in a union
58 being initialized cannot be converted to an expression, at least not until there are
59 improvements to StructLiterals.
60  */
61 
version(none)62 version (none)
63 {
64 struct Bug2850
65 {
66     union
67     {
68         int c;
69         double d;
70     }
71     int b;
72     int a;
73 }
74 
75 static assert(is(typeof(
76  () { enum Bug2850 w = {b:47, 714, d:4}; return w; }
77 )));
78 static assert(is(typeof(
79  () { enum Bug2850 w = {b:47, d:4}; return w; }
80 )));
81 // union not initialized
82 static assert(!is(typeof(
83  () { enum Bug2850 w = {b:47, 4}; return w; }
84 )));
85 // initializers for two fields in same union
86 static assert(!is(typeof(
87  () { enum Bug2850 w = {b:47, 4, c:5, 9}; return w; }
88 )));
89 
90 enum Bug2850 test2850 = {b:47, 714, d:23.1e-17};
91 
92 struct Horrid2850
93 {
94     union
95     {
96         int a;
97         int b;
98         struct
99         {
100             int c;
101             int d;
102         }
103     }
104     int f;
105     double q;
106 }
107 
108 enum Horrid2850 horrid2850 = {c:5,6};
109 Horrid2850 m2850 = {47, f:6};
110 Horrid2850 z2850 = {q:5, c:4, d:5};
111 
112 static assert(!is(typeof(
113  () { enum Horrid2850 w = {c:47, d:5, a:7}; return w; }
114 )));
115 
116 void test2()
117 {
118     assert(test2850.a == 714);
119     assert(test2850.b == 47);
120     assert(test2850.d == 23.1e-17);
121     assert(test2850.c != 0);
122 }
123 }
124 
125 /***** Bug 3779 *********************************/
126 
127 static const bug3779 = ["123"][0][$-1];
128 
129 /***** Bug 1880 *********************************/
130 
131 
132 enum Property1880 {First=1,Second=2}
133 
134 struct CompileTimeCheck1880(Property1880 Prop)
135 {
136     alias Prop prop;
137 }
138 Property1880 junkprop1880;
139 static assert(!is(CompileTimeCheck1880!(junkprop1880)));
140 
141 int main()
142 {
143     test1();
144 //    test2();
145 
146     printf("Success\n");
147     return 0;
148 }
149