]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gdc.test/runnable/interpret2.d
d: Import dmd b8384668f, druntime e6caaab9, phobos 5ab9ad256 (v2.098.0-beta.1)
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / runnable / interpret2.d
CommitLineData
5fee5ec3
IB
1/*
2RUN_OUTPUT:
3---
4Success
5---
6*/
7
8//import core.stdc.stdio;
b4c522fa
IB
9extern(C) int printf(const char*, ...);
10
11template Tuple(A...)
12{
13 alias A Tuple;
14}
15
16template eval(A...)
17{
18 const typeof(A[0]) eval = A[0];
19}
20
21/************************************************/
22
23int foo1()
24{
25 int x;
26 foreach (i; 0 .. 10)
27 x += i;
28 return x;
29}
30
31int bar1()
32{
33 int x;
34 foreach_reverse (i; 0 .. 10)
35 {
36 x <<= 1;
37 x += i;
38 }
39 return x;
40}
41
42void 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
5fee5ec3 61/***** https://issues.dlang.org/show_bug.cgi?id=2850 *****/
b4c522fa
IB
62
63/* These tests are not passing, and shouldn't pass. A non-first field in a union
64being initialized cannot be converted to an expression, at least not until there are
65improvements to StructLiterals.
66 */
67
68version (none)
69{
70struct Bug2850
71{
72 union
73 {
74 int c;
75 double d;
76 }
77 int b;
78 int a;
79}
80
81static assert(is(typeof(
82 () { enum Bug2850 w = {b:47, 714, d:4}; return w; }
83)));
84static assert(is(typeof(
85 () { enum Bug2850 w = {b:47, d:4}; return w; }
86)));
87// union not initialized
88static assert(!is(typeof(
89 () { enum Bug2850 w = {b:47, 4}; return w; }
90)));
91// initializers for two fields in same union
92static assert(!is(typeof(
93 () { enum Bug2850 w = {b:47, 4, c:5, 9}; return w; }
94)));
95
96enum Bug2850 test2850 = {b:47, 714, d:23.1e-17};
97
98struct 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
114enum Horrid2850 horrid2850 = {c:5,6};
115Horrid2850 m2850 = {47, f:6};
116Horrid2850 z2850 = {q:5, c:4, d:5};
117
118static assert(!is(typeof(
119 () { enum Horrid2850 w = {c:47, d:5, a:7}; return w; }
120)));
121
122void 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
5fee5ec3 131/***** https://issues.dlang.org/show_bug.cgi?id=3779 *****/
b4c522fa
IB
132
133static const bug3779 = ["123"][0][$-1];
134
5fee5ec3 135/***** https://issues.dlang.org/show_bug.cgi?id=1880 *****/
b4c522fa
IB
136
137
138enum Property1880 {First=1,Second=2}
139
140struct CompileTimeCheck1880(Property1880 Prop)
141{
142 alias Prop prop;
143}
144Property1880 junkprop1880;
145static assert(!is(CompileTimeCheck1880!(junkprop1880)));
146
147int main()
148{
149 test1();
150// test2();
151
152 printf("Success\n");
153 return 0;
154}