1 // PERMUTE_ARGS:
2 
3 extern(C) int printf(const char*, ...);
4 
5 /**********************************************/
6 
7 enum Bar
8 {
9     bar2 = 2,
10     bar3,
11     bar4 = 0
12 }
13 
test1()14 void test1()
15 {
16     Bar b;
17 
18     assert(b == 2);
19 }
20 
21 /**********************************************/
22 
test2()23 void test2()
24 {
25     enum E
26     {
27         a=-1
28     }
29 
30     assert(E.min == -1);
31     assert(E.max == -1);
32 }
33 
34 
35 /**********************************************/
36 
test3()37 void test3()
38 {
39     enum E
40     {
41         a = 1,
42         b = -1,
43         c = 3,
44         d = 2
45     }
46 
47     assert(E.min == -1);
48     assert(E.max == 3);
49 }
50 
51 /**********************************************/
52 
test4()53 void test4()
54 {
55     enum E
56     {
57         a = -1,
58         b = -1,
59         c = -3,
60         d = -3
61     }
62 
63     assert(E.min==-3);
64     assert(E.max==-1);
65 }
66 
67 /**********************************************/
68 
69 enum Enum5
70 {
71     A = 3,
72     B = 10,
73     E = -5,
74 }
75 
test5()76 void test5()
77 {
78     assert(Enum5.init == Enum5.A);
79     assert(Enum5.init == 3);
80     Enum5 e;
81     assert(e == Enum5.A);
82     assert(e == 3);
83 }
84 
85 /***********************************/
86 
87 enum E6 : byte
88 {
89     NORMAL_VALUE = 0,
90     REFERRING_VALUE = NORMAL_VALUE + 1,
91     OTHER_NORMAL_VALUE = 2
92 }
93 
foo6(E6 e)94 void foo6(E6 e)
95 {
96 }
97 
test6()98 void test6()
99 {
100      foo6(E6.NORMAL_VALUE);
101      foo6(E6.REFERRING_VALUE);
102      foo6(E6.OTHER_NORMAL_VALUE);
103 }
104 
105 /**********************************************/
106 // 2407
107 
108 int i2407;
109 
add2407()110 void add2407() { ++i2407; }
sub2407()111 void sub2407() { --i2407; }
112 
113 enum EF2407f : void function()
114 {
115     a = &add2407,
116     s = &sub2407,
117 }
118 
119 enum EF2407s
120 {
121     a = &add2407,
122     s = &sub2407,
123 }
124 
125 enum
126 {
127     a2407 = &add2407,
128     s2407 = &sub2407,
129 }
130 
function()131 enum : void function()
132 {
133     at2407 = &add2407,
134     st2407 = &sub2407,
135 }
136 
137 enum EEF2407 : EF2407s
138 {
139     a = EF2407s.a,
140     s = EF2407s.s,
141 }
142 
test2407()143 void test2407()
144 {
145     alias i2407 i;
146 
147     EF2407f.a();
148     assert(i == 1);
149     EF2407f.s();
150     assert(i == 0);
151 
152     EF2407s.a();
153     assert(i == 1);
154     EF2407s.s();
155     assert(i == 0);
156 
157     a2407();
158     assert(i == 1);
159     s2407();
160     assert(i == 0);
161 
162     at2407();
163     assert(i == 1);
164     st2407();
165     assert(i == 0);
166 
167     EEF2407.a();
168     assert(i == 1);
169     EEF2407.s();
170     assert(i == 0);
171 
172     EEF2407.init();
173     assert(i == 1);
174 
175     struct S { int i; }
176     enum ES : S
177     {
178         a = S(1),
179         b = S(3),
180         c = S(2),
181     }
182     static assert(ES.init == S(1));
183     static assert(!__traits(compiles, ES.min));
184     static assert(!__traits(compiles, ES.max));
185 
186     enum EES : ES
187     {
188         a = ES.a,
189         b = ES.b,
190         c = ES.c,
191     }
192     static assert(EES.init == ES.init);
193     static assert(EES.init == S(1));
194     static assert(!__traits(compiles, EES.min));
195     static assert(!__traits(compiles, EES.max));
196 
197     ES es = ES.c;
198     assert(es.i == 2);
199     es = ES.b;
200     assert(es.i == 3);
201 
202     class C { this(int i) { this.i = i; } int i; }
203     enum EC : C
204     {
205         a = new C(42),
206         b = null,
207         c = new C(1),
208         d = new C(33),
209     }
210     static assert(EC.init.i == (new C(42)).i);
211     static assert(!__traits(compiles, EC.min));
212     static assert(!__traits(compiles, EC.max));
213 
214     EC ec = EC.d;
215     assert(ec.i == 33);
216     ec = EC.b;
217     assert(ec is null);
218 }
219 
220 /**********************************************/
221 // 3096
222 
test3096()223 void test3096()
224 {
225     template Tuple(T...) { alias Tuple = T; }
226 
227     template Base(E)
228     {
229         static if(is(E B == enum))
230             alias Base = B;
231     }
232 
233     template GetEnum(T)
234     {
235         enum GetEnum { v = T.init }
236     }
237 
238     struct S { }
239     class C { }
240 
241     foreach (Type; Tuple!(char, wchar, dchar, byte, ubyte,
242                           short, ushort, int, uint, long,
243                           ulong, float, double, real, S, C))
244     {
245         static assert(is(Base!(GetEnum!Type) == Type));
246     }
247 }
248 
249 /**********************************************/
250 // 7719
251 
252 enum foo7719 = bar7719;
253 enum { bar7719 = 1 }
254 
255 /**********************************************/
256 // 9845
257 
258 enum { A9845 = B9845 }
259 enum { B9845 = 1 }
260 
261 /**********************************************/
262 // 9846
263 
264 const int A9846 = B9846;
265 enum { B9846 = 1 }
266 
267 /**********************************************/
268 // 10105
269 
270 enum E10105 : char[1] { a = "a" }
271 
272 /**********************************************/
273 // 10113
274 
275 enum E10113 : string
276 {
277     a = "a",
278     b = "b",
279     abc = "abc"
280 }
281 
282 void test10113()
283 {
284     E10113 v = E10113.b;
285     bool check = false;
286 
287     final switch (v) {
288     case E10113.a: assert(false);
289     case E10113.b: check = true; break;
290     case E10113.abc: assert(false);
291     }
292 
293     assert(check);
294 }
295 
296 /**********************************************/
297 // 10503
298 
299 @property int octal10503(string num)()
300 {
301     return num.length;
302 }
303 
304 enum
305 {
306     A10503 = octal10503!"2000000",
307     B10503 = octal10503!"4000",
308 }
309 
310 /**********************************************/
311 // 10505
312 
313 enum
314 {
315     a10505 = true,
316     b10505 = 10.0f,
317     c10505 = false,
318     d10505 = 10,
319     e10505 = null
320 }
321 
322 static assert(is(typeof(a10505) == bool));
323 static assert(is(typeof(b10505) == float));
324 static assert(is(typeof(c10505) == bool));
325 static assert(is(typeof(d10505) == int));
326 static assert(is(typeof(e10505) == typeof(null)));
327 
328 /**********************************************/
329 // 10561
330 
331 void test10561()
332 {
333     template Tuple(T...) { alias Tuple = T; }
334 
335     foreach (Type; Tuple!(char, wchar, dchar, byte, ubyte,
336                           short, ushort, int, uint, long,
337                           ulong, float, double, real))
338     {
339         enum : Type { v = 0, w = 0, x, y = x }
340         static assert(is(typeof(v) == Type));
341         static assert(is(typeof(w) == Type));
342         static assert(is(typeof(x) == Type));
343         static assert(is(typeof(y) == Type));
344     }
345 
346     class B { }
347     class D : B { }
348     enum : B { a = new D, b = new B, c = null }
349     static assert(is(typeof(a) == B));
350     static assert(is(typeof(b) == B));
351     static assert(is(typeof(c) == B));
352 
353     struct S { this(int) { } }
354     enum : S { d = S(1), e = S(2) }
355     static assert(is(typeof(d) == S));
356     static assert(is(typeof(e) == S));
357 
358     enum : float[] { f = [], g = [1.0, 2.0], h = [1.0f] }
359     static assert(is(typeof(f) == float[]));
360     static assert(is(typeof(g) == float[]));
361     static assert(is(typeof(h) == float[]));
362 }
363 
364 /**********************************************/
365 // 10612
366 
367 int[E10612] ie10612;
368 E10612[int] ei10612;
369 E10612[E10612] ee10612;
370 
371 enum E10612 { a }
372 
373 /**********************************************/
374 // 10788
375 
376 enum v10788 = e10788;
377 enum : int { e10788 }
378 
379 /**********************************************/
380 
381 class C7
382 {
383     enum Policy
384     {
385         PREFER_READERS,
386         PREFER_WRITERS
387     }
388 
389     void foo1( Policy policy = Policy.PREFER_READERS ) { }
390     void foo2( Policy policy = Policy.PREFER_WRITERS ) { }
391 }
392 
393 /**********************************************/
394 
395 void test8()
396 {
397     enum E
398     {
399         A = B,
400         E = D + 7,
401         B = 3,
402         C,
403         D,
404     }
405 
406     assert(E.A == 3);
407     assert(E.B == 3);
408     assert(E.C == 4);
409     assert(E.D == 5);
410     assert(E.E == 12);
411     assert(E.max == 12);
412 }
413 
414 /**********************************************/
415 // 13220
416 
417 enum E13220a;
418 @(1) enum E13220b;
419 
420 void test13220()
421 {
422     auto prot = __traits(getProtection, E13220a);
423     assert(prot == "public");
424 
425     auto udas = __traits(getAttributes, E13220b);
426     assert(udas[0] == 1);
427 }
428 
429 /**********************************************/
430 
431 int main()
432 {
433     test1();
434     test2();
435     test3();
436     test4();
437     test5();
438     test6();
439     test2407();
440     test10113();
441     test10561();
442     test8();
443     test13220();
444 
445     printf("Success\n");
446     return 0;
447 }
448