Debian Codegraph @

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

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