152
|
1 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94777
|
|
2 // { dg-additional-options "-fmain -funittest" }
|
|
3 // { dg-do run { target hw } }
|
|
4 // { dg-skip-if "needs gcc/config.d" { ! d_runtime } }
|
|
5
|
|
6 void testVariadic(T)(int nargs, ...)
|
|
7 {
|
|
8 import core.stdc.stdarg;
|
|
9 foreach(i; 0 .. nargs)
|
|
10 {
|
|
11 auto arg = va_arg!T(_argptr);
|
|
12 static if (__traits(compiles, arg.value))
|
|
13 {
|
|
14 assert(arg.value == i);
|
|
15 }
|
|
16 else static if (__traits(compiles, arg[0]))
|
|
17 {
|
|
18 foreach (value; arg)
|
|
19 assert(value == i);
|
|
20 }
|
|
21 else
|
|
22 {
|
|
23 assert(arg == T.init);
|
|
24 }
|
|
25 }
|
|
26 }
|
|
27
|
|
28 /******************************************/
|
|
29
|
|
30 struct Constructor
|
|
31 {
|
|
32 static int count;
|
|
33 int value;
|
|
34 this(int v) { count++; this.value = v; }
|
|
35 }
|
|
36
|
|
37 unittest
|
|
38 {
|
|
39 auto a0 = Constructor(0);
|
|
40 auto a1 = Constructor(1);
|
|
41 auto a2 = Constructor(2);
|
|
42 testVariadic!Constructor(3, a0, a1, a2);
|
|
43 assert(Constructor.count == 3);
|
|
44 }
|
|
45
|
|
46 /******************************************/
|
|
47
|
|
48 struct Postblit
|
|
49 {
|
|
50 static int count = 0;
|
|
51 int value;
|
|
52 this(this) { count++; }
|
|
53 }
|
|
54
|
|
55 unittest
|
|
56 {
|
|
57 auto a0 = Postblit(0);
|
|
58 auto a1 = Postblit(1);
|
|
59 auto a2 = Postblit(2);
|
|
60 testVariadic!Postblit(3, a0, a1, a2);
|
|
61 assert(Postblit.count == 3);
|
|
62 }
|
|
63
|
|
64 /******************************************/
|
|
65
|
|
66 struct Destructor
|
|
67 {
|
|
68 static int count = 0;
|
|
69 int value;
|
|
70 ~this() { count++; }
|
|
71 }
|
|
72
|
|
73 unittest
|
|
74 {
|
|
75 {
|
|
76 auto a0 = Destructor(0);
|
|
77 auto a1 = Destructor(1);
|
|
78 auto a2 = Destructor(2);
|
|
79 static assert(!__traits(compiles, testVariadic!Destructor(3, a0, a1, a2)));
|
|
80 }
|
|
81 assert(Destructor.count == 3);
|
|
82 }
|
|
83
|
|
84 /******************************************/
|
|
85
|
|
86 struct CopyConstructor
|
|
87 {
|
|
88 static int count = 0;
|
|
89 int value;
|
|
90 this(int v) { this.value = v; }
|
|
91 this(ref typeof(this) other) { count++; this.value = other.value; }
|
|
92 }
|
|
93
|
|
94 unittest
|
|
95 {
|
|
96 auto a0 = CopyConstructor(0);
|
|
97 auto a1 = CopyConstructor(1);
|
|
98 auto a2 = CopyConstructor(2);
|
|
99 testVariadic!CopyConstructor(3, a0, a1, a2);
|
|
100 // NOTE: Cpctors are not implemented yet.
|
|
101 assert(CopyConstructor.count == 0 || CopyConstructor.count == 3);
|
|
102 }
|
|
103
|
|
104 /******************************************/
|
|
105
|
|
106 unittest
|
|
107 {
|
|
108 struct Nested
|
|
109 {
|
|
110 int value;
|
|
111 }
|
|
112
|
|
113 auto a0 = Nested(0);
|
|
114 auto a1 = Nested(1);
|
|
115 auto a2 = Nested(2);
|
|
116 testVariadic!Nested(3, a0, a1, a2);
|
|
117 }
|
|
118
|
|
119 /******************************************/
|
|
120
|
|
121 unittest
|
|
122 {
|
|
123 struct Nested2
|
|
124 {
|
|
125 int value;
|
|
126 }
|
|
127
|
|
128 void testVariadic2(int nargs, ...)
|
|
129 {
|
|
130 import core.stdc.stdarg;
|
|
131 foreach(i; 0 .. nargs)
|
|
132 {
|
|
133 auto arg = va_arg!Nested2(_argptr);
|
|
134 assert(arg.value == i);
|
|
135 }
|
|
136 }
|
|
137
|
|
138 auto a0 = Nested2(0);
|
|
139 auto a1 = Nested2(1);
|
|
140 auto a2 = Nested2(2);
|
|
141 testVariadic2(3, a0, a1, a2);
|
|
142 }
|
|
143
|
|
144 /******************************************/
|
|
145
|
|
146 struct EmptyStruct
|
|
147 {
|
|
148 }
|
|
149
|
|
150 unittest
|
|
151 {
|
|
152 auto a0 = EmptyStruct();
|
|
153 auto a1 = EmptyStruct();
|
|
154 auto a2 = EmptyStruct();
|
|
155 testVariadic!EmptyStruct(3, a0, a1, a2);
|
|
156 }
|
|
157
|
|
158 /******************************************/
|
|
159
|
|
160 alias StaticArray = int[4];
|
|
161
|
|
162 unittest
|
|
163 {
|
|
164 StaticArray a0 = 0;
|
|
165 StaticArray a1 = 1;
|
|
166 StaticArray a2 = 2;
|
|
167 // XBUG: Front-end rewrites static arrays as dynamic arrays.
|
|
168 //testVariadic!StaticArray(3, a0, a1, a2);
|
|
169 }
|
|
170
|
|
171 /******************************************/
|
|
172
|
|
173 alias EmptyArray = void[0];
|
|
174
|
|
175 unittest
|
|
176 {
|
|
177 auto a0 = EmptyArray.init;
|
|
178 auto a1 = EmptyArray.init;
|
|
179 auto a2 = EmptyArray.init;
|
|
180 testVariadic!EmptyArray(3, a0, a1, a2);
|
|
181 }
|