d: Merge upstream dmd, druntime 4c18eed967, phobos d945686a4.
[official-gcc.git] / gcc / testsuite / gdc.test / compilable / dtoh_TemplateDeclaration.d
blob6fefcceeb976067bdca846d01531655ad1c07c9b
1 /*
2 REQUIRED_ARGS: -HC -c -o-
3 PERMUTE_ARGS:
4 TEST_OUTPUT:
5 ---
6 // Automatically generated by Digital Mars D Compiler
8 #pragma once
10 #include <assert.h>
11 #include <math.h>
12 #include <stddef.h>
13 #include <stdint.h>
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
22 size_t length;
23 T *ptr;
25 _d_dynamicArray() : length(0), ptr(NULL) { }
27 _d_dynamicArray(size_t length_in, T *ptr_in)
28 : length(length_in), ptr(ptr_in) { }
30 T& operator[](const size_t idx) {
31 assert(idx < length);
32 return ptr[idx];
35 const T& operator[](const size_t idx) const {
36 assert(idx < length);
37 return ptr[idx];
40 #endif
42 struct Outer final
44 int32_t a;
45 struct Member final
47 typedef int32_t Nested;
48 Member()
53 Outer() :
54 a()
57 Outer(int32_t a) :
58 a(a)
62 enum : int32_t { SomeOtherLength = 1 };
64 struct ActualBuffer final
66 ActualBuffer()
71 template <typename T>
72 struct A final
74 T x;
75 enum : int32_t { Enum = 42 };
77 static int32_t GsharedNum;
78 const int32_t MemNum;
79 void foo();
80 A()
85 template <typename T>
86 struct NotInstantiated final
88 NotInstantiated()
93 struct B final
95 A<int32_t > x;
96 B() :
97 x()
100 B(A<int32_t > x) :
101 x(x)
105 template <typename T>
106 struct Foo final
108 T val;
109 Foo()
114 template <typename T>
115 struct Bar final
117 Foo<T > v;
118 Bar()
123 template <typename T>
124 struct Array final
126 typedef Array This;
127 typedef typeof(1 + 2) Int;
128 typedef typeof(T::a) IC;
129 Array(size_t dim);
130 ~Array();
131 void get() const;
132 template <typename T>
133 bool opCast() const;
134 typename T::Member i;
135 typename Outer::Member::Nested j;
136 void visit(typename T::Member::Nested i);
137 Array()
142 template <typename T, typename U>
143 extern T foo(U u);
145 extern A<A<int32_t > > aaint;
147 template <typename T>
148 class Parent
150 public:
151 T parentMember;
152 void parentFinal();
153 virtual void parentVirtual();
156 template <typename T>
157 class Child final : public Parent<T >
159 public:
160 T childMember;
161 void parentVirtual() override;
162 T childFinal();
165 extern void withDefTempl(A<int32_t > a = A<int32_t >(2, 13));
167 template <typename T>
168 extern void withDefTempl2(A<T > a = static_cast<A<T >>(A<T >(2)));
170 class ChildInt : public Parent<int32_t >
174 struct HasMixins final
176 void foo(int32_t t);
177 HasMixins()
182 template <typename T>
183 struct HasMixinsTemplate final
185 void foo(T t);
186 HasMixinsTemplate()
191 extern HasMixinsTemplate<bool > hmti;
193 template <typename T>
194 struct NotAA final
196 enum : int32_t { length = 12 };
198 T buffer[length];
199 T otherBuffer[SomeOtherLength];
200 T calcBuffer[foo(1)];
201 NotAA()
206 template <typename Buffer>
207 struct BufferTmpl final
209 Buffer buffer;
210 Buffer buffer2;
211 BufferTmpl()
216 struct ImportedBuffer final
218 typedef ActualBuffer Buffer;
219 ActualBuffer buffer2;
220 ImportedBuffer() :
221 buffer2()
224 ImportedBuffer(ActualBuffer buffer2) :
225 buffer2(buffer2)
231 extern (C++) struct A(T)
233 T x;
234 enum Enum = 42;
235 __gshared GsharedNum = 43;
236 immutable MemNum = 13;
237 void foo() {}
240 // Invalid declarations accepted because it's not instantiated
241 extern (C++) struct NotInstantiated(T)
243 enum T noInit;
244 enum missingSem = T.init;
247 extern (C++) struct B
249 A!int x;
252 // https://issues.dlang.org/show_bug.cgi?id=20604
253 extern(C++)
255 struct Foo (T)
257 T val;
260 struct Bar (T)
262 Foo!T v;
266 extern (C++) struct Array(T)
268 alias This = typeof(this);
269 alias Int = typeof(1 + 2);
270 alias IC = typeof(T.a);
272 this(size_t dim) pure nothrow {}
273 @disable this(this);
274 ~this() {}
275 void get() const {}
277 bool opCast(T)() const pure nothrow @nogc @safe
278 if (is(T == bool))
280 return str.ptr !is null;
283 T.Member i;
284 Outer.Member.Nested j;
285 void visit(T.Member.Nested i) {}
288 struct Outer
290 int a;
291 static struct Member
293 alias Nested = int;
297 // alias AO = Array!Outer;
299 extern(C++) T foo(T, U)(U u) { return T.init; }
301 extern(C++) __gshared A!(A!int) aaint;
303 extern(C++) class Parent(T)
305 T parentMember;
306 final void parentFinal() {}
307 void parentVirtual() {}
310 extern(C++) final class Child(T) : Parent!T
312 T childMember;
313 override void parentVirtual() {}
314 T childFinal() { return T.init; }
317 extern(C++) void withDefTempl(A!int a = A!int(2)) {}
319 extern(C++) void withDefTempl2(T)(A!T a = A!T(2)) {}
321 extern(C++) alias withDefTempl2Inst = withDefTempl2!int;
323 extern(C++) class ChildInt : Parent!int {}
325 /******************************************************
326 * Mixins
329 extern (C++):
331 mixin template MixinA(T)
333 void foo(T t) {}
336 mixin template MixinB() {}
338 struct HasMixins
340 mixin MixinA!int;
341 mixin MixinB;
344 struct HasMixinsTemplate(T)
346 mixin MixinA!T;
347 mixin MixinB;
350 __gshared HasMixinsTemplate!bool hmti;
352 /// Declarations that look like associative arrays
354 extern(D) enum SomeOtherLength = 1;
356 struct NotAA(T)
358 private:
359 enum length = 12;
360 public:
361 T[length] buffer;
362 T[SomeOtherLength] otherBuffer;
363 T[foo(1)] calcBuffer;
366 // Same name but hidden by the template paramter
367 extern (D) struct Buffer {}
368 extern (D) struct ActualBuffer {}
370 struct BufferTmpl(Buffer)
372 Buffer buffer;
373 mixin BufferMixin!();
376 struct ImportedBuffer
378 alias Buffer = ActualBuffer;
379 mixin BufferMixin!();
382 mixin template BufferMixin()
384 Buffer buffer2;