1 module issues;
2 
3 
4 import extra: String, MethodParamString;
5 import core.time: Duration;
6 
7 struct Uncopiable {
8     @disable this(this);
9     double x;
10     double fun() @safe @nogc pure nothrow const { return x * 2; }
11 }
12 
13 /**
14    Here to make sure it's not wrapped and doesn't cause problems.
15    See #10.
16  */
17 export auto uncopiable() {
18     return Uncopiable.init;
19 }
20 
21 
22 export auto uncopiablePtr(double d = 33.3) {
23     return new Uncopiable(d);
24 }
25 
26 
27 
28 // FIXME - Can't spell out the name of an inner struct in the mixin
29 // that calls createPythonModule
30 // See https://github.com/symmetryinvestments/autowrap/issues/130
31 version(Have_autowrap_pynih) { }
32 else {
33     export auto stringPtr(string s) {
34         static struct StringPtrRetStruct {
35             string value;
36         }
37         return new StringPtrRetStruct(s);
38     }
39 }
40 
41 
42 // Generates symbols with two leading underscores
43 struct DoubleUnderscore {
44     static struct Inner {
45         this(this) {}
46         ~this() {}
47     }
48 
49     Inner inner;
50 
51     this(this) { }
52     ~this() {}
53 }
54 
55 
56 struct IssueString {
57     string value;
58     this(string value) { this.value = value; }
59 }
60 
61 export void takesInString(in IssueString str) {
62 
63 }
64 
65 export void takesScopeString(scope IssueString str) {
66 
67 }
68 
69 export void takesRefString(ref IssueString str) {
70 
71 }
72 
73 
74 export void takesRefConstString(ref const(IssueString) str) {
75 
76 }
77 
78 
79 export ref const(IssueString) returnsRefConstString() {
80     static IssueString ret = IssueString("quux");
81     return ret;
82 }
83 
84 export const(IssueString) returnsConstString() {
85     return const IssueString("toto");
86 }
87 
88 
89 export extern(C) int cAdd(int i, int j) {
90     return i + j;
91 }
92 
93 
94 export extern(C++) int cppAdd(int i, int j) {
95     return i + j;
96 }
97 
98 
99 struct StaticMemberFunctions {
100     static int add(int i, int j) {
101         return i + j;
102     }
103 }
104 
105 
106 class Issue54 {
107     int i;
108     this(int i) { this.i = i; }
109 }
110 
111 export void takesString(String str) {
112 
113 }
114 
115 
116 class Issue153 {
117 
118     int i;
119 
120     this(int i) @safe @nogc pure nothrow {
121         this.i = i;
122     }
123 
124     void toString(scope void delegate(in char[]) sink) const {
125         import std.conv: text;
126         sink("Issue153(");
127         sink(i.text);
128         sink(")");
129     }
130 }
131 
132 
133 struct Socket {
134     size_t send(const(void)[] bytes) {
135         return bytes.length;
136     }
137 }
138 
139 
140 class MyException: Exception {
141     import std.exception: basicExceptionCtors;
142     mixin basicExceptionCtors;
143 }
144 
145 class Issue161: MyException {
146     int errorCode;
147 
148     this(string msg,
149          string file = __FILE__,
150          size_t line = __LINE__,
151          Throwable next = null,
152          int err = _lasterr(),
153          string function(int) @trusted errorFormatter = &formatSocketError)
154     {
155         errorCode = err;
156 
157         if (msg.length)
158             super(msg ~ ": " ~ errorFormatter(err), file, line, next);
159         else
160             super(errorFormatter(err), file, line, next);
161     }
162 
163     this(string msg,
164          Throwable next,
165          string file = __FILE__,
166          size_t line = __LINE__,
167          int err = _lasterr(),
168          string function(int) @trusted errorFormatter = &formatSocketError)
169     {
170         this(msg, file, line, next, err, errorFormatter);
171     }
172 
173     this(string msg,
174          int err,
175          string function(int) @trusted errorFormatter = &formatSocketError,
176          string file = __FILE__,
177          size_t line = __LINE__,
178          Throwable next = null)
179     {
180         this(msg, file, line, next, err, errorFormatter);
181     }
182 }
183 
184 version(Windows) {
185     private int _lasterr() nothrow @nogc {
186         return WSAGetLastError();
187     }
188 } else {
189     private int _lasterr() nothrow @nogc {
190         import core.stdc.errno;
191         // return errno;
192         return 42;
193     }
194 }
195 
196 
197 private string formatSocketError(int err) @trusted
198 {
199     return "oops";
200 }
201 
202 
203 export void issue163(out int[] ints) {
204     ints ~= 42;
205 }
206 
207 
208 struct Issue164 {
209     size_t strlen(MethodParamString s) {
210         return s.value.length;
211     }
212 }
213 
214 
215 export int issue166_days(Duration dur) {
216     return cast(int) dur.total!"days";
217 }
218 
219 
220 export int issue166_secs(Duration dur) {
221     return cast(int) dur.total!"seconds";
222 }
223 
224 
225 export int issue166_usecs(Duration dur) {
226     return cast(int) dur.total!"usecs";
227 }
228 
229 
230 struct Issue198 {
231 
232     ubyte[] bytes;
233 
234     void[] opSlice(ulong start, ulong end) {
235         return bytes[start .. end];
236     }
237 
238     ubyte opIndex(ulong i) {
239         return 42;
240     }
241 
242     auto length() @property @safe @nogc pure const {
243         return bytes.length;
244     }
245 }
246 
247 
248 // infinite range
249 struct FortyTwos {
250     int i;  // why not
251     enum empty = false;
252     int front() { return 42; }
253     void popFront() {}
254     auto save() { return this; }
255     string toString() {
256         import std.conv: text;
257         return i.text;
258     }
259 }
260 
261 
262 union Union {
263     void* ptr;
264     int fd;
265     uint u32;
266     ulong u64;
267 }
268 
269 
270 struct Issue256 {
271     import std.typecons: Nullable;
272     import std.datetime: Date;
273     Date date;
274     Nullable!int maybeInt;
275     Nullable!Date maybeDate;
276 }
277 
278 
279 struct MethodWithScopeSafeDelegate {
280     // has to have indirection to trigger the issue due to scope
281     static struct Struct { string s; }
282     int fun(int i, int delegate(int, double, scope Struct) nothrow @safe cb) {
283         return cb(i, 33.3, Struct());
284     }
285 }
286 
287 
288 struct Issue268 {
289     int i;
290 }
291 
292 
293 struct Issue271 {
294     string value;
295     alias value this;
296 }
297 
298 
299 struct Struct279 {
300     int i;
301     this(int i) @safe @nogc pure scope { this.i = i; }
302     bool opEquals(typeof(this) other) @safe @nogc pure scope const {
303         return i == other.i;
304     }
305 }
306 
307 
308 class Class279 {
309     int i;
310     this(int i) @safe @nogc pure scope { this.i = i; }
311 
312     override bool opEquals(Object obj) @safe pure scope const {
313         auto other = cast(typeof(this)) obj;
314         if(other is null) throw new Exception("Can only compare to Class279, not " ~ typeid(obj).toString);
315         return i == other.i;
316     }
317 }
318 
319 struct DummyInt {
320     int i;
321     this(int i) @safe @nogc pure scope { this.i = i; }
322 }