1 /+
2 REQUIRED_ARGS: -o- -HC
3 TEST_OUTPUT:
4 ---
5 // Automatically generated by Digital Mars D Compiler
6
7 #pragma once
8
9 #include <assert.h>
10 #include <stddef.h>
11 #include <stdint.h>
12 #include <math.h>
13
14 #ifdef CUSTOM_D_ARRAY_TYPE
15 #define _d_dynamicArray CUSTOM_D_ARRAY_TYPE
16 #else
17 /// Represents a D [] array
18 template<typename T>
19 struct _d_dynamicArray final
20 {
21 size_t length;
22 T *ptr;
23
24 _d_dynamicArray() : length(0), ptr(NULL) { }
25
26 _d_dynamicArray(size_t length_in, T *ptr_in)
27 : length(length_in), ptr(ptr_in) { }
28
29 T& operator[](const size_t idx) {
30 assert(idx < length);
31 return ptr[idx];
32 }
33
34 const T& operator[](const size_t idx) const {
35 assert(idx < length);
36 return ptr[idx];
37 }
38 };
39 #endif
40
41 class ExternDClass;
42 struct ExternDStruct2;
43 struct ExternDStruct3;
44
45 struct ExternDStruct final
46 {
47 int32_t i;
48 double d;
49 ExternDStruct() :
50 i(),
51 d()
52 {
53 }
54 ExternDStruct(int32_t i, double d = NAN) :
55 i(i),
56 d(d)
57 {}
58 };
59
60 enum class ExternDEnum
61 {
62 A = 0,
63 };
64
65 template <>
66 struct ExternDStructTemplate final
67 {
68 // Ignoring var i alignment 0
69 int32_t i;
70 // Ignoring var d alignment 0
71 double d;
72 ExternDStructTemplate()
73 {
74 }
75 };
76
77 class Object
78 {
79 virtual void __vtable_slot_0();
80 virtual void __vtable_slot_1();
81 virtual void __vtable_slot_2();
82 virtual void __vtable_slot_3();
83 public:
84 class Monitor
85 {
86 virtual void __vtable_slot_4();
87 virtual void __vtable_slot_5();
88 };
89
90 };
91
92 class ExternDClass : public Object
93 {
94 public:
95 int32_t i;
96 double d;
97 };
98
99 struct ExternDStruct2 final
100 {
101 int32_t doStuff();
102 ExternDStruct2()
103 {
104 }
105 };
106
107 struct ExternDStruct3 final
108 {
109 int32_t a;
110 ExternDStruct3() :
111 a()
112 {
113 }
114 ExternDStruct3(int32_t a) :
115 a(a)
116 {}
117 };
118
119 namespace ExternDEnum2
120 {
121 static ExternDStruct3 const A = ExternDStruct3(1);
122 };
123
124 struct ExternCppStruct final
125 {
126 ExternDStruct s;
127 ExternDEnum e;
128 ExternDStructTemplate< > st;
129 ExternCppStruct() :
130 s(),
131 st()
132 {
133 }
134 ExternCppStruct(ExternDStruct s, ExternDEnum e = (ExternDEnum)0, ExternDStructTemplate< > st = ExternDStructTemplate< >(0, NAN)) :
135 s(s),
136 e(e),
137 st(st)
138 {}
139 };
140
141 extern ExternDClass* globalC;
142
143 extern void foo(int32_t arg = globalC.i);
144
145 extern ExternDStruct2* globalS2;
146
147 extern void bar(int32_t arg = globalS2->doStuff());
148
149 extern /* ExternDEnum2 */ ExternDStruct3* globalE2;
150
151 extern void baz(int32_t arg = globalE2->a);
152 ---
153
154 Known issues:
155 - class declarations must be emitted on member access
156 +/
157
158 // extern(D) symbols are ignored upon first visit but required later
159
160 struct ExternDStruct
161 {
162 int i;
163 double d;
164
165 // None of these can be emitted due to the mismatched mangling
166 static double staticDouble;
167 static shared double staticSharedDouble;
168 __gshared double sharedDouble;
169 }
170
171 struct ExternDStruct2
172 {
doStuff()173 extern(C++) int doStuff()
174 {
175 return 1;
176 }
177 }
178
179 struct ExternDStruct3
180 {
181 int a;
182 }
183
184 class ExternDClass
185 {
186 int i;
187 double d;
188 }
189
190 enum ExternDEnum
191 {
192 A
193 }
194
195 enum ExternDEnum2 : ExternDStruct3
196 {
197 A = ExternDStruct3(1)
198 }
199
ExternDStructTemplate()200 struct ExternDStructTemplate()
201 {
202 int i;
203 double d;
204 }
205
206 extern (C++):
207
208 struct ExternCppStruct
209 {
210 ExternDStruct s;
211 ExternDEnum e;
212 ExternDStructTemplate!() st;
213 }
214
215 __gshared ExternDClass globalC;
216
217 void foo(int arg = globalC.i) {}
218
219 __gshared ExternDStruct2* globalS2;
220
221 void bar(int arg = globalS2.doStuff()) {}
222
223 __gshared ExternDEnum2* globalE2;
224
225 void baz(int arg = globalE2.a) {}
226