Debian Codegraph @

.cargo/vendor/cbindgen/tests/expectations/destructor_and_copy_ctor.cpp

raw
1 #define NOINLINE __attribute__((noinline))
2 #define NODISCARD [[nodiscard]]
3
4
5 #include <cstdarg>
6 #include <cstdint>
7 #include <cstdlib>
8 #include <ostream>
9 #include <new>
10
11 enum class FillRule : uint8_t {
12 A,
13 B,
14 };
15
16 /// This will have a destructor manually implemented via variant_body, and
17 /// similarly a Drop impl in Rust.
18 template<typename T>
19 struct OwnedSlice {
20 uintptr_t len;
21 T *ptr;
22 ~OwnedSlice() {}
23 };
24
25 template<typename LengthPercentage>
26 struct Polygon {
27 FillRule fill;
28 OwnedSlice<LengthPercentage> coordinates;
29 };
30
31 template<typename T>
32 struct Foo {
33 enum class Tag : uint8_t {
34 Bar,
35 Polygon1,
36 Slice1,
37 Slice2,
38 Slice3,
39 Slice4,
40 };
41
42 struct Polygon1_Body {
43 Polygon<T> _0;
44 };
45
46 struct Slice1_Body {
47 OwnedSlice<T> _0;
48 };
49
50 struct Slice2_Body {
51 OwnedSlice<int32_t> _0;
52 };
53
54 struct Slice3_Body {
55 FillRule fill;
56 OwnedSlice<T> coords;
57 };
58
59 struct Slice4_Body {
60 FillRule fill;
61 OwnedSlice<int32_t> coords;
62 };
63
64 Tag tag;
65 union {
66 Polygon1_Body polygon1;
67 Slice1_Body slice1;
68 Slice2_Body slice2;
69 Slice3_Body slice3;
70 Slice4_Body slice4;
71 };
72
73 static Foo Bar() {
74 Foo result;
75 result.tag = Tag::Bar;
76 return result;
77 }
78
79 bool IsBar() const {
80 return tag == Tag::Bar;
81 }
82
83 static Foo Polygon1(const Polygon<T> &_0) {
84 Foo result;
85 ::new (&result.polygon1._0) (Polygon<T>)(_0);
86 result.tag = Tag::Polygon1;
87 return result;
88 }
89
90 bool IsPolygon1() const {
91 return tag == Tag::Polygon1;
92 }
93
94 static Foo Slice1(const OwnedSlice<T> &_0) {
95 Foo result;
96 ::new (&result.slice1._0) (OwnedSlice<T>)(_0);
97 result.tag = Tag::Slice1;
98 return result;
99 }
100
101 bool IsSlice1() const {
102 return tag == Tag::Slice1;
103 }
104
105 static Foo Slice2(const OwnedSlice<int32_t> &_0) {
106 Foo result;
107 ::new (&result.slice2._0) (OwnedSlice<int32_t>)(_0);
108 result.tag = Tag::Slice2;
109 return result;
110 }
111
112 bool IsSlice2() const {
113 return tag == Tag::Slice2;
114 }
115
116 static Foo Slice3(const FillRule &fill,
117 const OwnedSlice<T> &coords) {
118 Foo result;
119 ::new (&result.slice3.fill) (FillRule)(fill);
120 ::new (&result.slice3.coords) (OwnedSlice<T>)(coords);
121 result.tag = Tag::Slice3;
122 return result;
123 }
124
125 bool IsSlice3() const {
126 return tag == Tag::Slice3;
127 }
128
129 static Foo Slice4(const FillRule &fill,
130 const OwnedSlice<int32_t> &coords) {
131 Foo result;
132 ::new (&result.slice4.fill) (FillRule)(fill);
133 ::new (&result.slice4.coords) (OwnedSlice<int32_t>)(coords);
134 result.tag = Tag::Slice4;
135 return result;
136 }
137
138 bool IsSlice4() const {
139 return tag == Tag::Slice4;
140 }
141
142 private:
143 Foo() {
144
145 }
146 public:
147
148
149 ~Foo() {
150 switch (tag) {
151 case Tag::Polygon1: polygon1.~Polygon1_Body(); break;
152 case Tag::Slice1: slice1.~Slice1_Body(); break;
153 case Tag::Slice2: slice2.~Slice2_Body(); break;
154 case Tag::Slice3: slice3.~Slice3_Body(); break;
155 case Tag::Slice4: slice4.~Slice4_Body(); break;
156 default: break;
157 }
158 }
159
160 Foo(const Foo& other)
161 : tag(other.tag) {
162 switch (tag) {
163 case Tag::Polygon1: ::new (&polygon1) (Polygon1_Body)(other.polygon1); break;
164 case Tag::Slice1: ::new (&slice1) (Slice1_Body)(other.slice1); break;
165 case Tag::Slice2: ::new (&slice2) (Slice2_Body)(other.slice2); break;
166 case Tag::Slice3: ::new (&slice3) (Slice3_Body)(other.slice3); break;
167 case Tag::Slice4: ::new (&slice4) (Slice4_Body)(other.slice4); break;
168 default: break;
169 }
170 }
171 Foo& operator=(const Foo& other) {
172 if (this != &other) {
173 this->~Foo();
174 new (this) Foo(other);
175 }
176 return *this;
177 }
178 };
179
180 template<typename T>
181 union Baz {
182 enum class Tag : uint8_t {
183 Bar2,
184 Polygon21,
185 Slice21,
186 Slice22,
187 Slice23,
188 Slice24,
189 };
190
191 struct Polygon21_Body {
192 Tag tag;
193 Polygon<T> _0;
194 };
195
196 struct Slice21_Body {
197 Tag tag;
198 OwnedSlice<T> _0;
199 };
200
201 struct Slice22_Body {
202 Tag tag;
203 OwnedSlice<int32_t> _0;
204 };
205
206 struct Slice23_Body {
207 Tag tag;
208 FillRule fill;
209 OwnedSlice<T> coords;
210 };
211
212 struct Slice24_Body {
213 Tag tag;
214 FillRule fill;
215 OwnedSlice<int32_t> coords;
216 };
217
218 struct {
219 Tag tag;
220 };
221 Polygon21_Body polygon21;
222 Slice21_Body slice21;
223 Slice22_Body slice22;
224 Slice23_Body slice23;
225 Slice24_Body slice24;
226
227 static Baz Bar2() {
228 Baz result;
229 result.tag = Tag::Bar2;
230 return result;
231 }
232
233 bool IsBar2() const {
234 return tag == Tag::Bar2;
235 }
236
237 static Baz Polygon21(const Polygon<T> &_0) {
238 Baz result;
239 ::new (&result.polygon21._0) (Polygon<T>)(_0);
240 result.tag = Tag::Polygon21;
241 return result;
242 }
243
244 bool IsPolygon21() const {
245 return tag == Tag::Polygon21;
246 }
247
248 static Baz Slice21(const OwnedSlice<T> &_0) {
249 Baz result;
250 ::new (&result.slice21._0) (OwnedSlice<T>)(_0);
251 result.tag = Tag::Slice21;
252 return result;
253 }
254
255 bool IsSlice21() const {
256 return tag == Tag::Slice21;
257 }
258
259 static Baz Slice22(const OwnedSlice<int32_t> &_0) {
260 Baz result;
261 ::new (&result.slice22._0) (OwnedSlice<int32_t>)(_0);
262 result.tag = Tag::Slice22;
263 return result;
264 }
265
266 bool IsSlice22() const {
267 return tag == Tag::Slice22;
268 }
269
270 static Baz Slice23(const FillRule &fill,
271 const OwnedSlice<T> &coords) {
272 Baz result;
273 ::new (&result.slice23.fill) (FillRule)(fill);
274 ::new (&result.slice23.coords) (OwnedSlice<T>)(coords);
275 result.tag = Tag::Slice23;
276 return result;
277 }
278
279 bool IsSlice23() const {
280 return tag == Tag::Slice23;
281 }
282
283 static Baz Slice24(const FillRule &fill,
284 const OwnedSlice<int32_t> &coords) {
285 Baz result;
286 ::new (&result.slice24.fill) (FillRule)(fill);
287 ::new (&result.slice24.coords) (OwnedSlice<int32_t>)(coords);
288 result.tag = Tag::Slice24;
289 return result;
290 }
291
292 bool IsSlice24() const {
293 return tag == Tag::Slice24;
294 }
295
296 private:
297 Baz() {
298
299 }
300 public:
301
302
303 ~Baz() {
304 switch (tag) {
305 case Tag::Polygon21: polygon21.~Polygon21_Body(); break;
306 case Tag::Slice21: slice21.~Slice21_Body(); break;
307 case Tag::Slice22: slice22.~Slice22_Body(); break;
308 case Tag::Slice23: slice23.~Slice23_Body(); break;
309 case Tag::Slice24: slice24.~Slice24_Body(); break;
310 default: break;
311 }
312 }
313
314 Baz(const Baz& other)
315 : tag(other.tag) {
316 switch (tag) {
317 case Tag::Polygon21: ::new (&polygon21) (Polygon21_Body)(other.polygon21); break;
318 case Tag::Slice21: ::new (&slice21) (Slice21_Body)(other.slice21); break;
319 case Tag::Slice22: ::new (&slice22) (Slice22_Body)(other.slice22); break;
320 case Tag::Slice23: ::new (&slice23) (Slice23_Body)(other.slice23); break;
321 case Tag::Slice24: ::new (&slice24) (Slice24_Body)(other.slice24); break;
322 default: break;
323 }
324 }
325 Baz& operator=(const Baz& other) {
326 if (this != &other) {
327 this->~Baz();
328 new (this) Baz(other);
329 }
330 return *this;
331 }
332 };
333
334 union Taz {
335 enum class Tag : uint8_t {
336 Bar3,
337 Taz1,
338 Taz3,
339 };
340
341 struct Taz1_Body {
342 Tag tag;
343 int32_t _0;
344 };
345
346 struct Taz3_Body {
347 Tag tag;
348 OwnedSlice<int32_t> _0;
349 };
350
351 struct {
352 Tag tag;
353 };
354 Taz1_Body taz1;
355 Taz3_Body taz3;
356
357 static Taz Bar3() {
358 Taz result;
359 result.tag = Tag::Bar3;
360 return result;
361 }
362
363 bool IsBar3() const {
364 return tag == Tag::Bar3;
365 }
366
367 static Taz Taz1(const int32_t &_0) {
368 Taz result;
369 ::new (&result.taz1._0) (int32_t)(_0);
370 result.tag = Tag::Taz1;
371 return result;
372 }
373
374 bool IsTaz1() const {
375 return tag == Tag::Taz1;
376 }
377
378 static Taz Taz3(const OwnedSlice<int32_t> &_0) {
379 Taz result;
380 ::new (&result.taz3._0) (OwnedSlice<int32_t>)(_0);
381 result.tag = Tag::Taz3;
382 return result;
383 }
384
385 bool IsTaz3() const {
386 return tag == Tag::Taz3;
387 }
388
389 private:
390 Taz() {
391
392 }
393 public:
394
395
396 ~Taz() {
397 switch (tag) {
398 case Tag::Taz1: taz1.~Taz1_Body(); break;
399 case Tag::Taz3: taz3.~Taz3_Body(); break;
400 default: break;
401 }
402 }
403
404 Taz(const Taz& other)
405 : tag(other.tag) {
406 switch (tag) {
407 case Tag::Taz1: ::new (&taz1) (Taz1_Body)(other.taz1); break;
408 case Tag::Taz3: ::new (&taz3) (Taz3_Body)(other.taz3); break;
409 default: break;
410 }
411 }
412 Taz& operator=(const Taz& other) {
413 if (this != &other) {
414 this->~Taz();
415 new (this) Taz(other);
416 }
417 return *this;
418 }
419 };
420
421 union Tazz {
422 enum class Tag : uint8_t {
423 Bar4,
424 Taz2,
425 };
426
427 struct Taz2_Body {
428 Tag tag;
429 int32_t _0;
430 };
431
432 struct {
433 Tag tag;
434 };
435 Taz2_Body taz2;
436
437 static Tazz Bar4() {
438 Tazz result;
439 result.tag = Tag::Bar4;
440 return result;
441 }
442
443 bool IsBar4() const {
444 return tag == Tag::Bar4;
445 }
446
447 static Tazz Taz2(const int32_t &_0) {
448 Tazz result;
449 ::new (&result.taz2._0) (int32_t)(_0);
450 result.tag = Tag::Taz2;
451 return result;
452 }
453
454 bool IsTaz2() const {
455 return tag == Tag::Taz2;
456 }
457
458 private:
459 Tazz() {
460
461 }
462 public:
463
464 };
465
466 union Tazzz {
467 enum class Tag : uint8_t {
468 Bar5,
469 Taz5,
470 };
471
472 struct Taz5_Body {
473 Tag tag;
474 int32_t _0;
475 };
476
477 struct {
478 Tag tag;
479 };
480 Taz5_Body taz5;
481
482 static Tazzz Bar5() {
483 Tazzz result;
484 result.tag = Tag::Bar5;
485 return result;
486 }
487
488 bool IsBar5() const {
489 return tag == Tag::Bar5;
490 }
491
492 static Tazzz Taz5(const int32_t &_0) {
493 Tazzz result;
494 ::new (&result.taz5._0) (int32_t)(_0);
495 result.tag = Tag::Taz5;
496 return result;
497 }
498
499 bool IsTaz5() const {
500 return tag == Tag::Taz5;
501 }
502
503 private:
504 Tazzz() {
505
506 }
507 public:
508
509
510 ~Tazzz() {
511 switch (tag) {
512 case Tag::Taz5: taz5.~Taz5_Body(); break;
513 default: break;
514 }
515 }
516
517 Tazzz(const Tazzz& other)
518 : tag(other.tag) {
519 switch (tag) {
520 case Tag::Taz5: ::new (&taz5) (Taz5_Body)(other.taz5); break;
521 default: break;
522 }
523 }
524 };
525
526 union Tazzzz {
527 enum class Tag : uint8_t {
528 Taz6,
529 Taz7,
530 };
531
532 struct Taz6_Body {
533 Tag tag;
534 int32_t _0;
535 };
536
537 struct Taz7_Body {
538 Tag tag;
539 uint32_t _0;
540 };
541
542 struct {
543 Tag tag;
544 };
545 Taz6_Body taz6;
546 Taz7_Body taz7;
547
548 static Tazzzz Taz6(const int32_t &_0) {
549 Tazzzz result;
550 ::new (&result.taz6._0) (int32_t)(_0);
551 result.tag = Tag::Taz6;
552 return result;
553 }
554
555 bool IsTaz6() const {
556 return tag == Tag::Taz6;
557 }
558
559 static Tazzzz Taz7(const uint32_t &_0) {
560 Tazzzz result;
561 ::new (&result.taz7._0) (uint32_t)(_0);
562 result.tag = Tag::Taz7;
563 return result;
564 }
565
566 bool IsTaz7() const {
567 return tag == Tag::Taz7;
568 }
569
570 private:
571 Tazzzz() {
572
573 }
574 public:
575
576
577 ~Tazzzz() {
578 switch (tag) {
579 case Tag::Taz6: taz6.~Taz6_Body(); break;
580 case Tag::Taz7: taz7.~Taz7_Body(); break;
581
582 }
583 }
584
585 Tazzzz(const Tazzzz& other)
586 : tag(other.tag) {
587 switch (tag) {
588 case Tag::Taz6: ::new (&taz6) (Taz6_Body)(other.taz6); break;
589 case Tag::Taz7: ::new (&taz7) (Taz7_Body)(other.taz7); break;
590
591 }
592 }
593 Tazzzz& operator=(const Tazzzz& other) {
594 if (this != &other) {
595 this->~Tazzzz();
596 new (this) Tazzzz(other);
597 }
598 return *this;
599 }
600 };
601
602 union Qux {
603 enum class Tag : uint8_t {
604 Qux1,
605 Qux2,
606 };
607
608 struct Qux1_Body {
609 Tag tag;
610 int32_t _0;
611
612 bool operator==(const Qux1_Body& other) const {
613 return _0 == other._0;
614 }
615 };
616
617 struct Qux2_Body {
618 Tag tag;
619 uint32_t _0;
620
621 bool operator==(const Qux2_Body& other) const {
622 return _0 == other._0;
623 }
624 };
625
626 struct {
627 Tag tag;
628 };
629 Qux1_Body qux1;
630 Qux2_Body qux2;
631
632 static Qux Qux1(const int32_t &_0) {
633 Qux result;
634 ::new (&result.qux1._0) (int32_t)(_0);
635 result.tag = Tag::Qux1;
636 return result;
637 }
638
639 bool IsQux1() const {
640 return tag == Tag::Qux1;
641 }
642
643 static Qux Qux2(const uint32_t &_0) {
644 Qux result;
645 ::new (&result.qux2._0) (uint32_t)(_0);
646 result.tag = Tag::Qux2;
647 return result;
648 }
649
650 bool IsQux2() const {
651 return tag == Tag::Qux2;
652 }
653
654 NODISCARD bool operator==(const Qux& other) const {
655 if (tag != other.tag) {
656 return false;
657 }
658 switch (tag) {
659 case Tag::Qux1: return qux1 == other.qux1;
660 case Tag::Qux2: return qux2 == other.qux2;
661
662 }
663 return true;
664 }
665
666 NODISCARD bool operator!=(const Qux& other) const {
667 return !(*this == other);
668 }
669
670 private:
671 Qux() {
672
673 }
674 public:
675
676
677 NOINLINE ~Qux() {
678 switch (tag) {
679 case Tag::Qux1: qux1.~Qux1_Body(); break;
680 case Tag::Qux2: qux2.~Qux2_Body(); break;
681
682 }
683 }
684
685 NOINLINE Qux(const Qux& other)
686 : tag(other.tag) {
687 switch (tag) {
688 case Tag::Qux1: ::new (&qux1) (Qux1_Body)(other.qux1); break;
689 case Tag::Qux2: ::new (&qux2) (Qux2_Body)(other.qux2); break;
690
691 }
692 }
693 NOINLINE Qux& operator=(const Qux& other) {
694 if (this != &other) {
695 this->~Qux();
696 new (this) Qux(other);
697 }
698 return *this;
699 }
700 };
701
702 extern "C" {
703
704 void root(const Foo<uint32_t> *a,
705 const Baz<int32_t> *b,
706 const Taz *c,
707 Tazz d,
708 const Tazzz *e,
709 const Tazzzz *f,
710 const Qux *g);
711
712 } // extern "C"