]>
Commit | Line | Data |
---|---|---|
5fee5ec3 IB |
1 | /* |
2 | REQUIRED_ARGS: -HC -c -o- | |
3 | PERMUTE_ARGS: | |
4 | TEST_OUTPUT: | |
5 | --- | |
6 | // Automatically generated by Digital Mars D Compiler | |
7 | ||
8 | #pragma once | |
9 | ||
10 | #include <assert.h> | |
5eb9927a | 11 | #include <math.h> |
5fee5ec3 IB |
12 | #include <stddef.h> |
13 | #include <stdint.h> | |
5fee5ec3 IB |
14 | |
15 | #ifdef CUSTOM_D_ARRAY_TYPE | |
16 | #define _d_dynamicArray CUSTOM_D_ARRAY_TYPE | |
17 | #else | |
18 | /// Represents a D [] array | |
19 | template<typename T> | |
20 | struct _d_dynamicArray final | |
21 | { | |
22 | size_t length; | |
23 | T *ptr; | |
24 | ||
25 | _d_dynamicArray() : length(0), ptr(NULL) { } | |
26 | ||
27 | _d_dynamicArray(size_t length_in, T *ptr_in) | |
28 | : length(length_in), ptr(ptr_in) { } | |
29 | ||
30 | T& operator[](const size_t idx) { | |
31 | assert(idx < length); | |
32 | return ptr[idx]; | |
33 | } | |
34 | ||
35 | const T& operator[](const size_t idx) const { | |
36 | assert(idx < length); | |
37 | return ptr[idx]; | |
38 | } | |
39 | }; | |
40 | #endif | |
41 | ||
42 | typedef uint$?:32=32|64=64$_t size_t; | |
43 | ||
44 | struct Outer final | |
45 | { | |
46 | int32_t a; | |
47 | struct Member final | |
48 | { | |
49 | typedef int32_t Nested; | |
50 | Member() | |
51 | { | |
52 | } | |
53 | }; | |
54 | ||
55 | Outer() : | |
56 | a() | |
57 | { | |
58 | } | |
59 | Outer(int32_t a) : | |
60 | a(a) | |
61 | {} | |
62 | }; | |
63 | ||
64 | enum : int32_t { SomeOtherLength = 1 }; | |
65 | ||
66 | struct ActualBuffer final | |
67 | { | |
68 | ActualBuffer() | |
69 | { | |
70 | } | |
71 | }; | |
72 | ||
73 | template <typename T> | |
74 | struct A final | |
75 | { | |
5fee5ec3 | 76 | T x; |
5fee5ec3 IB |
77 | enum : int32_t { Enum = 42 }; |
78 | ||
5fee5ec3 | 79 | static int32_t GsharedNum; |
5fee5ec3 IB |
80 | const int32_t MemNum; |
81 | void foo(); | |
82 | A() | |
83 | { | |
84 | } | |
85 | }; | |
86 | ||
87 | template <typename T> | |
88 | struct NotInstantiated final | |
89 | { | |
5fee5ec3 IB |
90 | NotInstantiated() |
91 | { | |
92 | } | |
93 | }; | |
94 | ||
95 | struct B final | |
96 | { | |
97 | A<int32_t > x; | |
98 | B() : | |
99 | x() | |
100 | { | |
101 | } | |
102 | B(A<int32_t > x) : | |
103 | x(x) | |
104 | {} | |
105 | }; | |
106 | ||
107 | template <typename T> | |
108 | struct Foo final | |
109 | { | |
5fee5ec3 IB |
110 | T val; |
111 | Foo() | |
112 | { | |
113 | } | |
114 | }; | |
115 | ||
116 | template <typename T> | |
117 | struct Bar final | |
118 | { | |
5fee5ec3 IB |
119 | Foo<T > v; |
120 | Bar() | |
121 | { | |
122 | } | |
123 | }; | |
124 | ||
125 | template <typename T> | |
126 | struct Array final | |
127 | { | |
128 | typedef Array This; | |
129 | typedef typeof(1 + 2) Int; | |
130 | typedef typeof(T::a) IC; | |
131 | Array(size_t dim); | |
132 | ~Array(); | |
133 | void get() const; | |
134 | template <typename T> | |
135 | bool opCast() const; | |
5fee5ec3 | 136 | typename T::Member i; |
5fee5ec3 IB |
137 | typename Outer::Member::Nested j; |
138 | void visit(typename T::Member::Nested i); | |
139 | Array() | |
140 | { | |
141 | } | |
142 | }; | |
143 | ||
144 | template <typename T, typename U> | |
145 | extern T foo(U u); | |
146 | ||
147 | extern A<A<int32_t > > aaint; | |
148 | ||
149 | template <typename T> | |
150 | class Parent | |
151 | { | |
5fee5ec3 IB |
152 | public: |
153 | T parentMember; | |
154 | void parentFinal(); | |
155 | virtual void parentVirtual(); | |
156 | }; | |
157 | ||
158 | template <typename T> | |
159 | class Child final : public Parent<T > | |
160 | { | |
5fee5ec3 IB |
161 | public: |
162 | T childMember; | |
610d7898 | 163 | void parentVirtual() override; |
5fee5ec3 IB |
164 | T childFinal(); |
165 | }; | |
166 | ||
167 | extern void withDefTempl(A<int32_t > a = A<int32_t >(2, 13)); | |
168 | ||
169 | template <typename T> | |
170 | extern void withDefTempl2(A<T > a = static_cast<A<T >>(A<T >(2))); | |
171 | ||
172 | class ChildInt : public Parent<int32_t > | |
173 | { | |
174 | }; | |
175 | ||
176 | struct HasMixins final | |
177 | { | |
178 | void foo(int32_t t); | |
179 | HasMixins() | |
180 | { | |
181 | } | |
182 | }; | |
183 | ||
184 | template <typename T> | |
185 | struct HasMixinsTemplate final | |
186 | { | |
187 | void foo(T t); | |
188 | HasMixinsTemplate() | |
189 | { | |
190 | } | |
191 | }; | |
192 | ||
193 | extern HasMixinsTemplate<bool > hmti; | |
194 | ||
195 | template <typename T> | |
196 | struct NotAA final | |
197 | { | |
5fee5ec3 IB |
198 | enum : int32_t { length = 12 }; |
199 | ||
5fee5ec3 | 200 | T buffer[length]; |
5fee5ec3 | 201 | T otherBuffer[SomeOtherLength]; |
5fee5ec3 IB |
202 | T calcBuffer[foo(1)]; |
203 | NotAA() | |
204 | { | |
205 | } | |
206 | }; | |
207 | ||
208 | template <typename Buffer> | |
209 | struct BufferTmpl final | |
210 | { | |
5fee5ec3 | 211 | Buffer buffer; |
5fee5ec3 IB |
212 | Buffer buffer2; |
213 | BufferTmpl() | |
214 | { | |
215 | } | |
216 | }; | |
217 | ||
218 | struct ImportedBuffer final | |
219 | { | |
220 | typedef ActualBuffer Buffer; | |
221 | ActualBuffer buffer2; | |
d0e4bdcd GM |
222 | ImportedBuffer() : |
223 | buffer2() | |
5fee5ec3 IB |
224 | { |
225 | } | |
d0e4bdcd GM |
226 | ImportedBuffer(ActualBuffer buffer2) : |
227 | buffer2(buffer2) | |
228 | {} | |
5fee5ec3 IB |
229 | }; |
230 | --- | |
231 | */ | |
232 | ||
233 | extern (C++) struct A(T) | |
234 | { | |
235 | T x; | |
236 | enum Enum = 42; | |
237 | __gshared GsharedNum = 43; | |
238 | immutable MemNum = 13; | |
239 | void foo() {} | |
240 | } | |
241 | ||
242 | // Invalid declarations accepted because it's not instantiated | |
243 | extern (C++) struct NotInstantiated(T) | |
244 | { | |
245 | enum T noInit; | |
246 | enum missingSem = T.init; | |
247 | } | |
248 | ||
249 | extern (C++) struct B | |
250 | { | |
251 | A!int x; | |
252 | } | |
253 | ||
254 | // https://issues.dlang.org/show_bug.cgi?id=20604 | |
255 | extern(C++) | |
256 | { | |
257 | struct Foo (T) | |
258 | { | |
259 | T val; | |
260 | } | |
261 | ||
262 | struct Bar (T) | |
263 | { | |
264 | Foo!T v; | |
265 | } | |
266 | } | |
267 | ||
268 | extern (C++) struct Array(T) | |
269 | { | |
270 | alias This = typeof(this); | |
271 | alias Int = typeof(1 + 2); | |
272 | alias IC = typeof(T.a); | |
273 | ||
274 | this(size_t dim) pure nothrow {} | |
275 | @disable this(this); | |
276 | ~this() {} | |
277 | void get() const {} | |
278 | ||
279 | bool opCast(T)() const pure nothrow @nogc @safe | |
280 | if (is(T == bool)) | |
281 | { | |
282 | return str.ptr !is null; | |
283 | } | |
284 | ||
285 | T.Member i; | |
286 | Outer.Member.Nested j; | |
287 | void visit(T.Member.Nested i) {} | |
288 | } | |
289 | ||
290 | struct Outer | |
291 | { | |
292 | int a; | |
293 | static struct Member | |
294 | { | |
295 | alias Nested = int; | |
296 | } | |
297 | } | |
298 | ||
299 | // alias AO = Array!Outer; | |
300 | ||
301 | extern(C++) T foo(T, U)(U u) { return T.init; } | |
302 | ||
303 | extern(C++) __gshared A!(A!int) aaint; | |
304 | ||
305 | extern(C++) class Parent(T) | |
306 | { | |
307 | T parentMember; | |
308 | final void parentFinal() {} | |
309 | void parentVirtual() {} | |
310 | } | |
311 | ||
312 | extern(C++) final class Child(T) : Parent!T | |
313 | { | |
314 | T childMember; | |
315 | override void parentVirtual() {} | |
316 | T childFinal() { return T.init; } | |
317 | } | |
318 | ||
319 | extern(C++) void withDefTempl(A!int a = A!int(2)) {} | |
320 | ||
321 | extern(C++) void withDefTempl2(T)(A!T a = A!T(2)) {} | |
322 | ||
323 | extern(C++) alias withDefTempl2Inst = withDefTempl2!int; | |
324 | ||
325 | extern(C++) class ChildInt : Parent!int {} | |
326 | ||
327 | /****************************************************** | |
328 | * Mixins | |
329 | */ | |
330 | ||
331 | extern (C++): | |
332 | ||
333 | mixin template MixinA(T) | |
334 | { | |
335 | void foo(T t) {} | |
336 | } | |
337 | ||
338 | mixin template MixinB() {} | |
339 | ||
340 | struct HasMixins | |
341 | { | |
342 | mixin MixinA!int; | |
343 | mixin MixinB; | |
344 | } | |
345 | ||
346 | struct HasMixinsTemplate(T) | |
347 | { | |
348 | mixin MixinA!T; | |
349 | mixin MixinB; | |
350 | } | |
351 | ||
352 | __gshared HasMixinsTemplate!bool hmti; | |
353 | ||
354 | /// Declarations that look like associative arrays | |
355 | ||
356 | extern(D) enum SomeOtherLength = 1; | |
357 | ||
358 | struct NotAA(T) | |
359 | { | |
360 | private: | |
361 | enum length = 12; | |
362 | public: | |
363 | T[length] buffer; | |
364 | T[SomeOtherLength] otherBuffer; | |
365 | T[foo(1)] calcBuffer; | |
366 | } | |
367 | ||
368 | // Same name but hidden by the template paramter | |
369 | extern (D) struct Buffer {} | |
370 | extern (D) struct ActualBuffer {} | |
371 | ||
372 | struct BufferTmpl(Buffer) | |
373 | { | |
374 | Buffer buffer; | |
375 | mixin BufferMixin!(); | |
376 | } | |
377 | ||
378 | struct ImportedBuffer | |
379 | { | |
380 | alias Buffer = ActualBuffer; | |
381 | mixin BufferMixin!(); | |
382 | } | |
383 | ||
384 | mixin template BufferMixin() | |
385 | { | |
386 | Buffer buffer2; | |
387 | } |