1 module it.c.dstep.issues;
2 
3 import it;
4 
5 @("")
6 @Tags("dstep_issues")
7 @safe unittest {
8     shouldCompile(
9         C(
10             q{
11 
12             }
13         ),
14         D(
15             q{
16             }
17         ),
18     );
19 }
20 
21 
22 @("8")
23 @Tags("dstep_issues")
24 @safe unittest {
25     shouldCompile(
26         C(
27             `
28                 #include <stdint.h>
29 
30                 typedef struct rd_kafka {
31                 	int dummy;
32                 } rd_kafka_t;
33 
34                 typedef struct rd_kafka_topic {
35                 	int dummy;
36                 } rd_kafka_topic_t;
37 
38                 typedef struct rd_kafka_metadata {
39                         int         broker_cnt;     /* Number of brokers in 'brokers' */
40                         struct rd_kafka_metadata_broker *brokers;  /* Brokers */
41 
42                         int         topic_cnt;      /* Number of topics in 'topics' */
43                         struct rd_kafka_metadata_topic *topics;    /* Topics */
44 
45                         int32_t     orig_broker_id; /* Broker originating this metadata */
46                         char       *orig_broker_name; /* Name of originating broker */
47                 } rd_kafka_metadata_t;
48 
49                 rd_kafka_metadata (rd_kafka_t *rk, int all_topics,
50                                    rd_kafka_topic_t *only_rkt,
51                                    const struct rd_kafka_metadata **metadatap,
52                                    int timeout_ms);
53             `
54         ),
55         D(
56             q{
57                 rd_kafka_t kafka; kafka.dummy = 42;
58                 rd_kafka_topic_t topic; topic.dummy = 42;
59                 const(rd_kafka_metadata) *meta;
60                 rd_kafka_metadata_(&kafka, 42, &topic, &meta, 77);
61             }
62         ),
63     );
64 }
65 
66 
67 @("10")
68 @Tags("dstep_issues")
69 @safe unittest
70 {
71     shouldCompile(
72         C(
73             q{
74                 struct info {
75                     long remote_ip;
76                     int remote_port;
77                     int is_ssl;
78                     void *user_data;
79 
80                     struct mg_header {
81                         const char *name;
82                         const char *value;
83                     } headers[64];
84                 };
85             }
86         ),
87         D(
88             q{
89                 info inf;
90 
91                 inf.remote_ip = 42L;
92                 inf.remote_port = 42;
93                 inf.is_ssl = 33;
94                 inf.user_data = null;
95 
96                 inf.headers[63].name = "name".ptr;
97                 inf.headers[63].value = "value".ptr;
98 
99                 static assert( __traits(compiles, inf.headers[63].value));
100                 static assert(!__traits(compiles, inf.headers[64].value));
101             }
102         ),
103     );
104 }
105 
106 
107 @("20")
108 @Tags("dstep_issues")
109 @safe unittest {
110     shouldCompile(
111         C(
112             `
113                 #define X (1)
114                 #define Y ((float)-X)
115                 #define f(x, b) ((a) + (b))
116                 #define foo 1
117             `
118         ),
119         D(
120             q{
121                 static assert(X == 1);
122                 static assert(Y == -1.0);
123                 enum a = 2;
124                 static assert(f(7, 3) == 5);
125                 static assert(foo == 1);
126             }
127         ),
128     );
129 }
130 
131 @("38")
132 @Tags("dstep_issues")
133 @safe unittest {
134     shouldCompile(
135         C(
136             q{
137                 void foo();
138                 void bar(const char* fmt, ...);
139                 void baz(void);
140             }
141         ),
142         D(
143             q{
144                 foo();
145                 bar("foo".ptr, 1, 2, 3.0, "foo".ptr);
146                 baz();
147             }
148         ),
149     );
150 }
151 
152 @("46")
153 @Tags("dstep_issues")
154 @safe unittest {
155     shouldCompile(
156         C(
157             `
158                 typedef unsigned char __u8;
159                 typedef unsigned int __u32;
160                 typedef __signed__ long __s64;
161                 typedef unsigned long __u64;
162 
163                 struct stats_t {
164                     __u8 scale;
165                     union {
166                         __u64 uvalue;
167                         __s64 svalue;
168                     };
169                 } __attribute__ ((packed));
170 
171 
172                 #define MAX_STATS   4
173 
174                 struct fe_stats_t {
175                     __u8 len;
176                     struct stats_t stat[MAX_STATS];
177                 } __attribute__ ((packed));
178 
179                 struct property_t {
180                     __u32 cmd;
181                     __u32 reserved[3];
182                     union {
183                         __u32 data;
184                         struct fe_stats_t st;
185                         struct {
186                             __u8 data[32];
187                             __u32 len;
188                             __u32 reserved1[3];
189                             void *reserved2;
190                         } buffer;
191                     } u;
192                     int result;
193                 } __attribute__ ((packed));
194             `
195         ),
196         D(
197             q{
198             }
199         ),
200     );
201 }
202 
203 @("85")
204 @Tags("dstep_issues")
205 @safe unittest {
206     shouldCompile(
207         C(
208             `
209                 #include <stddef.h>
210                 int complex_forward (const double data[], const size_t stride, const size_t n, double result[]);
211             `
212         ),
213         D(
214             q{
215                 double* data;
216                 size_t stride;
217                 size_t n;
218                 double* result;
219                 int ret = complex_forward(data, stride, n, result);
220             }
221         ),
222     );
223 }
224 
225 
226 @("98")
227 @Tags("dstep_issues")
228 @safe unittest {
229     shouldCompile(
230         C(
231             q{
232                 struct timeval { };
233                 void term_await_started(const struct timeval *timeout);
234             }
235         ),
236         D(
237             q{
238                 timeval timeout;
239                 term_await_started(&timeout);
240             }
241         ),
242     );
243 }
244 
245 
246 @("102")
247 @Tags("dstep_issues")
248 @safe unittest {
249     shouldCompile(
250         C(
251             q{
252                 typedef struct _ProtobufCMethodDescriptor ProtobufCMethodDescriptor;
253 
254                 struct _ProtobufCMethodDescriptor
255                 {
256                     const char *name;
257                     const ProtobufCMethodDescriptor *input;
258                     const ProtobufCMethodDescriptor *output;
259                 };
260             }
261         ),
262         D(
263             q{
264                 ProtobufCMethodDescriptor desc;
265                 desc.name = "name".ptr;
266                 desc.input = &desc;
267                 desc.output = &desc;
268             }
269         ),
270     );
271 }
272 
273 
274 @("106")
275 @Tags("dstep_issues")
276 @safe unittest {
277     shouldCompile(
278         C(
279             q{
280                 float _Complex foo;
281                 double _Complex bar;
282                 long double _Complex baz;
283             }
284         ),
285         D(
286             q{
287 
288             }
289         ),
290     );
291 }
292 
293 @("107")
294 @Tags("dstep_issues")
295 @safe unittest {
296     shouldCompile(
297         C(
298             q{
299                 typedef struct foo foo;
300             }
301         ),
302         D(
303             q{
304                 foo* f = null;
305             }
306         ),
307     );
308 }
309 
310 @("114")
311 @Tags("dstep_issues")
312 @safe unittest {
313     shouldCompile(
314         C(
315             q{
316                 typedef struct _Foo_List {
317                     void *data;
318                     struct _Foo_List *next;
319                 } Foo_List;
320             }
321         ),
322         D(
323             q{
324                 Foo_List list;
325                 list.data = null;
326                 list.next = &list;
327             }
328         ),
329     );
330 }
331 
332 @("116")
333 @Tags("dstep_issues")
334 @safe unittest {
335     shouldCompile(
336         C(
337             q{
338                 int foo(void);
339 
340                 typedef int (*Fun0)(void);
341                 typedef int (*Fun1)(int (*param)(void));
342 
343                 struct Foo {
344                     int (*bar)(void);
345                 };
346             }
347         ),
348         D(
349             q{
350                 int f0 = Fun0.init();
351                 int f1 = Fun1.init(&foo);
352                 Foo foo;
353                 int res = foo.bar();
354             }
355         ),
356     );
357 }
358 
359 
360 @("123")
361 @Tags("dstep_issues")
362 @safe unittest {
363     shouldCompile(
364         C(
365             `
366                 #include <limits.h>
367                 #define TEST INT_MAX
368             `
369         ),
370         D(
371             q{
372                 static assert(TEST == INT_MAX);
373             }
374         ),
375     );
376 }
377 
378 @("137")
379 @Tags("dstep_issues")
380 @safe unittest {
381     shouldCompile(
382         C(
383             q{
384                 typedef struct {
385                     struct DB_vfs_s *vfs;
386                 } DB_FILE;
387 
388                 typedef int DB_playItem_t;
389 
390                 typedef struct DB_plugin_action_s {
391                     const char *title;
392                     const char *name;
393                     unsigned flags;
394                 } DB_plugin_action_t;
395 
396                 typedef struct DB_vfs_s {
397                     const char **(*get_schemes) (void);
398                     int (*is_streaming) (void); // return 1 if the plugin streaming data
399                     void (*abort) (DB_FILE *stream);
400                     const char * (*get_content_type) (DB_FILE *stream);
401                     void (*set_track) (DB_FILE *f, DB_playItem_t *it);
402                 } DB_vfs_t;
403             }
404         ),
405         D(
406             q{
407                 DB_FILE dbFile;
408                 dbFile.vfs = null;
409                 DB_plugin_action_t action;
410                 action.title = "title".ptr;
411                 action.name = "name".ptr;
412                 action.flags = 0u;
413 
414                 DB_vfs_t vfs;
415                 const(char)** schemes = vfs.get_schemes();
416                 int isStreaming = vfs.is_streaming();
417                 vfs.abort(&dbFile);
418                 const(char)* contentType = vfs.get_content_type(&dbFile);
419                 DB_playItem_t playItem;
420                 vfs.set_track(&dbFile, &playItem);
421             }
422         ),
423     );
424 }
425 
426 @("138")
427 @Tags("dstep_issues")
428 @safe unittest {
429     shouldCompile(
430         C(
431             q{
432                 extern const unsigned fe_bandwidth_name[8];
433                 extern const unsigned fe_bandwidth_name[8];
434             }
435         ),
436         D(
437             q{
438                 uint i = fe_bandwidth_name[7];
439             }
440         ),
441     );
442 }
443 
444 @("140")
445 @Tags("dstep_issues")
446 @safe unittest {
447     shouldCompile(
448         C(
449             q{
450                 typedef enum fe_delivery_system {
451                     SYS_UNDEFINED,
452                     SYS_DVBC_ANNEX_A,
453                 } fe_delivery_system_t;
454             }
455         ),
456         D(
457             q{
458                 const undef = fe_delivery_system_t.SYS_UNDEFINED;
459             }
460         ),
461     );
462 }
463 
464 
465 @("141")
466 @Tags("dstep_issues")
467 @safe unittest {
468     shouldCompile(
469         C(
470             `
471                 #define _IOC_NRSHIFT	0
472                 #define _IOC_TYPESHIFT	1
473                 #define _IOC_SIZESHIFT	2
474                 #define _IOC_DIRSHIFT	3
475 
476                 #define _IOC_NONE	0U
477                 #define _IOC_READ	2U
478 
479                 #define _IOC(dir,type,nr,size) \
480                 	(((dir)  << _IOC_DIRSHIFT) | \
481                 	 ((type) << _IOC_TYPESHIFT) | \
482                 	 ((nr)   << _IOC_NRSHIFT) | \
483                 	 ((size) << _IOC_SIZESHIFT))
484 
485                 #define _IOC_TYPECHECK(t) (sizeof(t))
486 
487                 #define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
488                 #define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),(_IOC_TYPECHECK(size)))
489 
490                 typedef struct { } foo_status_t;
491                 typedef unsigned int __u32;
492                 typedef unsigned short __u16;
493 
494                 #define FE_READ_STATUS _IOR('o', 69, foo_status_t)
495                 #define FE_READ_BER _IOR('o', 70, __u32)
496                 #define FE_READ_SIGNAL_STRENGTH _IOR('o', 71, __u16)
497                 #define FE_READ_SNR _IOR('o', 72, __u16)
498                 #define FE_READ_UNCORRECTED_BLOCKS _IOR('o', 73, __u32)
499             `
500         ),
501         D(
502             q{
503                 static assert(_IOC_NRSHIFT == 0);
504                 static assert(_IOC_TYPESHIFT == 1);
505                 static assert(_IOC(4, 5, 6, 7) == 62);
506                 static assert(_IOC_TYPECHECK(int) == 4);
507                 static assert(_IO(4, 5) == 13);
508                 static assert(_IOR(4, 5, 6) == 29);
509                 static assert(FE_READ_STATUS == 223);
510                 static assert(FE_READ_BER == 222);
511                 static assert(FE_READ_SIGNAL_STRENGTH == 223);
512                 static assert(FE_READ_SNR == 222);
513                 static assert(FE_READ_UNCORRECTED_BLOCKS == 223);
514             }
515         ),
516     );
517 }
518 
519 @("160")
520 @Tags("dstep_issues")
521 @safe unittest {
522     shouldCompile(
523         C(
524             q{
525                 typedef struct { } CXFile;
526                 typedef struct { } CXSourceLocation;
527                 typedef struct { } CXClientData;
528 
529                 typedef void (*CXInclusionVisitor)(CXFile included_file,
530                                                    CXSourceLocation* inclusion_stack,
531                                                    unsigned include_len,
532                                                    CXClientData client_data);
533             }
534         ),
535         D(
536             q{
537                 CXFile file;
538                 CXSourceLocation location;
539                 CXClientData data;
540                 CXInclusionVisitor.init(file, &location, 42u, data);
541             }
542         ),
543     );
544 }
545 
546 @("166.0")
547 @Tags("dstep_issues")
548 @safe unittest {
549     shouldCompile(
550         C(
551             `
552                 #define __FSID_T_TYPE struct { int __val[2]; }
553                 typedef  __FSID_T_TYPE __fsid_t;
554                 typedef __fsid_t fsid_t;
555             `
556         ),
557         D(
558             q{
559                 static assert(fsid_t.__val.length == 2);
560             }
561         ),
562     );
563 }
564 
565 @("166.1")
566 @Tags("dstep_issues")
567 @safe unittest {
568     shouldCompile(
569         C(
570             `
571                 #define FOO 2
572                 #define __FSID_T_TYPE struct { int __val[FOO]; }
573                 typedef  __FSID_T_TYPE __fsid_t;
574                 typedef __fsid_t fsid_t;
575             `
576         ),
577         D(
578             q{
579                 static assert(fsid_t.__val.length == 2);
580             }
581         ),
582     );
583 }
584 
585 
586 @("166.2")
587 @Tags("dstep_issues")
588 @safe unittest {
589     shouldCompile(
590         C(
591             `
592                 #define FOO 2
593                 #define BAR FOO
594                 #define __FSID_T_TYPE struct { int __val[BAR]; }
595                 typedef  __FSID_T_TYPE __fsid_t;
596                 typedef __fsid_t fsid_t;
597             `
598         ),
599         D(
600             q{
601                 static assert(fsid_t.__val.length == 2);
602             }
603         ),
604     );
605 }