1 /**
2    Github issues.
3  */
4 module issues;
5 
6 import it;
7 
8 @Tags("issue")
9 @("3")
10 @safe unittest {
11     shouldCompile(
12         C(
13             `
14                 #include <signal.h>
15             `
16         ),
17         D(
18             q{
19                 siginfo_t si;
20                 si._sifields._timer.si_tid = 2;
21                 static assert(is(typeof(si.si_signo) == int));
22                 static assert(is(typeof(si._sifields._timer.si_tid) == int),
23                               typeof(si._sifields._timer.si_tid).stringof);
24             }
25         ),
26     );
27 }
28 
29 
30 @Tags("issue")
31 @("4")
32 @safe unittest {
33     with(immutable IncludeSandbox()) {
34         writeFile("issue4.h",
35                   q{
36                       extern char *arr[9];
37                   });
38         writeFile("issue4.dpp",
39                   `
40                    #include "issue4.h"
41                   `);
42         runPreprocessOnly("issue4.dpp");
43         fileShouldContain("issue4.d", q{extern __gshared char*[9] arr;});
44     }
45 }
46 
47 @Tags("issue")
48 @("5")
49 @safe unittest {
50     shouldCompile(
51         C(
52             q{
53                 typedef enum zfs_error {
54                     EZFS_SUCCESS = 0,
55                     EZFS_NOMEM = 2000,
56                 };
57 
58                 typedef struct zfs_perm_node {
59                     char z_pname[4096];
60                 } zfs_perm_node_t;
61 
62                 typedef struct libzfs_handle libzfs_handle_t;
63             }
64         ),
65         D(
66             q{
67                 zfs_error e1 = EZFS_SUCCESS;
68                 zfs_error e2 = zfs_error.EZFS_SUCCESS;
69                 zfs_perm_node_t node;
70                 static assert(node.z_pname.sizeof == 4096);
71                 static assert(is(typeof(node.z_pname[0]) == char), (typeof(node.z_pname[0]).stringof));
72                 libzfs_handle_t* ptr;
73             }
74         ),
75     );
76 }
77 
78 @Tags("issue")
79 @("6")
80 @safe unittest {
81     with(immutable IncludeSandbox()) {
82         writeFile("issue6.h",
83                   q{
84                       char *getMessage();
85                   });
86         writeFile("issue6.dpp",
87                   `
88                    #include "issue6.h"
89                   `);
90         runPreprocessOnly("issue6.dpp");
91         fileShouldContain("issue6.d", q{char* getMessage() @nogc nothrow;});
92     }
93 }
94 
95 
96 @Tags("issue")
97 @("7")
98 @safe unittest {
99     shouldCompile(
100         C(
101             q{
102                 struct splitflags {
103                     int dryrun : 1;
104                     int import : 2;
105                     int name_flags;
106                     int foo: 3;
107                     int bar: 4;
108                     int suffix;
109                 };
110 
111                 struct other {
112                     int quux: 2;
113                     int toto: 3;
114                 };
115             }
116         ),
117         D(
118             q{
119                 static assert(splitflags.sizeof == 16);
120                 static assert(other.sizeof == 4);
121             }
122         ),
123     );
124 }
125 
126 @Tags("issue")
127 @("10")
128 @safe unittest {
129     shouldCompile(
130         C(
131             q{
132                 enum silly_name {
133                     FOO,
134                     BAR,
135                     BAZ,
136                 };
137 
138                 extern void silly_name(enum silly_name thingie);
139             }
140         ),
141         D(
142             q{
143                 silly_name_(silly_name.FOO);
144             }
145         ),
146     );
147 }
148 
149 @Tags("issue")
150 @("11")
151 @safe unittest {
152     shouldCompile(
153         C(
154             q{
155                 struct Foo;
156                 typedef struct Foo* FooPtr;
157             }
158         ),
159         D(
160             q{
161                 FooPtr f = null;
162                 static assert(!__traits(compiles, Foo()));
163             }
164         ),
165     );
166 }
167 
168 @Tags("issue")
169 @("14")
170 @safe unittest {
171     import dpp.runtime.options: Options;
172     with(immutable IncludeSandbox()) {
173 
174         writeFile("foo.h",
175                   q{
176                       typedef int foo;
177                   });
178 
179         runPreprocessOnly("foo.h").shouldThrowWithMessage(
180             "No .dpp input file specified\n" ~ Options.usage);
181     }
182 }
183 
184 @Tags("issue", "preprocessor")
185 @("22.1")
186 @safe unittest {
187     shouldCompile(
188         C(
189             `
190                 typedef struct {
191                     #ifdef __USE_XOPEN
192                         int fds_bits[42];
193                         #define __FDS_BITS(set) ((set)->fds_bits)
194                     #else
195                         int __fds_bits[42];
196                         #define __FDS_BITS(set) ((set)->__fds_bits)
197                     #endif
198                 } fd_set;
199             `
200         ),
201         D(
202             q{
203                 fd_set set;
204                 __FDS_BITS(set)[0] = 42;
205             }
206         ),
207     );
208 }
209 
210 @Tags("issue", "preprocessor")
211 @("22.2")
212 @safe unittest {
213     shouldCompile(
214         C(
215             `
216                 #define SIZEOF(x) (sizeof(x))
217             `
218         ),
219         D(
220             q{
221                 int i;
222                 static assert(SIZEOF(i) == 4);
223             }
224         ),
225     );
226 }
227 
228 @Tags("issue", "preprocessor")
229 @("22.3")
230 @safe unittest {
231     shouldCompile(
232         C(
233             `
234                 typedef long int __fd_mask;
235                 #define __NFDBITS (8 * (int) sizeof (__fd_mask))
236             `
237         ),
238         D(
239             q{
240                 import std.conv;
241                 static assert(__NFDBITS == 8 * c_long.sizeof,
242                               text("expected ", 8 * c_long.sizeof, ", got: ", __NFDBITS));
243             }
244         ),
245     );
246 }
247 
248 @Tags("issue", "preprocessor")
249 @("22.4")
250 @safe unittest {
251     shouldCompile(
252         C(
253             `
254                 typedef struct clist { struct list* next; };
255                 #define clist_next(iter) (iter ? (iter)->next : NULL)
256             `
257         ),
258         D(
259             q{
260                 clist l;
261                 auto next = clist_next(&l);
262             }
263         ),
264     );
265 }
266 
267 
268 
269 @Tags("issue", "collision", "issue24")
270 @("24.1")
271 @safe unittest {
272     shouldCompile(
273         C(
274             q{
275                 struct Bar {
276                     void (*Foo)(void); // this should get renamed as Foo_
277                     struct Foo* (*whatever)(void);
278                 };
279             }
280         ),
281         D(
282             q{
283             }
284         ),
285     );
286 }
287 
288 @Tags("issue", "collision", "issue24")
289 @("24.2")
290 @safe unittest {
291     shouldCompile(
292         C(
293             q{
294                 int foo(int, struct foo_data**);
295                 struct foo { int dummy; };
296                 struct foo_data { int dummy; };
297             }
298         ),
299         D(
300             q{
301                 foo_data** data;
302                 int ret = foo_(42, data);
303                 foo s;
304                 s.dummy = 33;
305                 foo_data fd;
306                 fd.dummy = 77;
307             }
308         ),
309     );
310 }
311 
312 
313 @Tags("issue")
314 @("33.1")
315 @safe unittest {
316     shouldCompile(
317         C(
318             q{
319                 void (*f)();
320             }
321         ),
322         D(
323             q{
324                 static extern(C) void printHello() { }
325                 f = &printHello;
326                 f();
327             }
328         ),
329     );
330 }
331 
332 @Tags("issue")
333 @("33.2")
334 @safe unittest {
335     shouldCompile(
336         C(
337             q{
338                 int (*f)();
339             }
340         ),
341         D(
342             q{
343                 static extern(C) int func() { return 42; }
344                 f = &func;
345                 int i = f();
346             }
347         ),
348     );
349 }