From 69b3d20a92c13d944a1c5accaa64891cbb567baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 22 Feb 2020 14:15:42 +0100 Subject: [PATCH] Add tests for #475. --- .../both/destructor-and-copy-ctor.c | 45 +++++- .../both/destructor-and-copy-ctor.compat.c | 57 ++++++- tests/expectations/destructor-and-copy-ctor.c | 45 +++++- .../destructor-and-copy-ctor.compat.c | 57 ++++++- .../expectations/destructor-and-copy-ctor.cpp | 143 +++++++++++++++++- .../tag/destructor-and-copy-ctor.c | 45 +++++- .../tag/destructor-and-copy-ctor.compat.c | 57 ++++++- tests/rust/destructor-and-copy-ctor.rs | 15 +- 8 files changed, 453 insertions(+), 11 deletions(-) diff --git a/tests/expectations/both/destructor-and-copy-ctor.c b/tests/expectations/both/destructor-and-copy-ctor.c index 45dfecd..44b3270 100644 --- a/tests/expectations/both/destructor-and-copy-ctor.c +++ b/tests/expectations/both/destructor-and-copy-ctor.c @@ -165,4 +165,47 @@ typedef union Tazz { Taz2_Body taz2; } Tazz; -void root(const Foo_u32 *a, const Baz_i32 *b, const Taz *c, Tazz d); +enum Tazzz_Tag { + Bar5, + Taz5, +}; +typedef uint8_t Tazzz_Tag; + +typedef struct Taz5_Body { + Tazzz_Tag tag; + int32_t _0; +} Taz5_Body; + +typedef union Tazzz { + Tazzz_Tag tag; + Taz5_Body taz5; +} Tazzz; + +enum Tazzzz_Tag { + Taz6, + Taz7, +}; +typedef uint8_t Tazzzz_Tag; + +typedef struct Taz6_Body { + Tazzzz_Tag tag; + int32_t _0; +} Taz6_Body; + +typedef struct Taz7_Body { + Tazzzz_Tag tag; + uint32_t _0; +} Taz7_Body; + +typedef union Tazzzz { + Tazzzz_Tag tag; + Taz6_Body taz6; + Taz7_Body taz7; +} Tazzzz; + +void root(const Foo_u32 *a, + const Baz_i32 *b, + const Taz *c, + Tazz d, + const Tazzz *e, + const Tazzzz *f); diff --git a/tests/expectations/both/destructor-and-copy-ctor.compat.c b/tests/expectations/both/destructor-and-copy-ctor.compat.c index 9398f78..22373a7 100644 --- a/tests/expectations/both/destructor-and-copy-ctor.compat.c +++ b/tests/expectations/both/destructor-and-copy-ctor.compat.c @@ -195,11 +195,66 @@ typedef union Tazz { Taz2_Body taz2; } Tazz; +enum Tazzz_Tag +#ifdef __cplusplus + : uint8_t +#endif // __cplusplus + { + Bar5, + Taz5, +}; +#ifndef __cplusplus +typedef uint8_t Tazzz_Tag; +#endif // __cplusplus + +typedef struct Taz5_Body { + Tazzz_Tag tag; + int32_t _0; +} Taz5_Body; + +typedef union Tazzz { + Tazzz_Tag tag; + Taz5_Body taz5; +} Tazzz; + +enum Tazzzz_Tag +#ifdef __cplusplus + : uint8_t +#endif // __cplusplus + { + Taz6, + Taz7, +}; +#ifndef __cplusplus +typedef uint8_t Tazzzz_Tag; +#endif // __cplusplus + +typedef struct Taz6_Body { + Tazzzz_Tag tag; + int32_t _0; +} Taz6_Body; + +typedef struct Taz7_Body { + Tazzzz_Tag tag; + uint32_t _0; +} Taz7_Body; + +typedef union Tazzzz { + Tazzzz_Tag tag; + Taz6_Body taz6; + Taz7_Body taz7; +} Tazzzz; + #ifdef __cplusplus extern "C" { #endif // __cplusplus -void root(const Foo_u32 *a, const Baz_i32 *b, const Taz *c, Tazz d); +void root(const Foo_u32 *a, + const Baz_i32 *b, + const Taz *c, + Tazz d, + const Tazzz *e, + const Tazzzz *f); #ifdef __cplusplus } // extern "C" diff --git a/tests/expectations/destructor-and-copy-ctor.c b/tests/expectations/destructor-and-copy-ctor.c index c5acef3..7df62b2 100644 --- a/tests/expectations/destructor-and-copy-ctor.c +++ b/tests/expectations/destructor-and-copy-ctor.c @@ -165,4 +165,47 @@ typedef union { Taz2_Body taz2; } Tazz; -void root(const Foo_u32 *a, const Baz_i32 *b, const Taz *c, Tazz d); +enum Tazzz_Tag { + Bar5, + Taz5, +}; +typedef uint8_t Tazzz_Tag; + +typedef struct { + Tazzz_Tag tag; + int32_t _0; +} Taz5_Body; + +typedef union { + Tazzz_Tag tag; + Taz5_Body taz5; +} Tazzz; + +enum Tazzzz_Tag { + Taz6, + Taz7, +}; +typedef uint8_t Tazzzz_Tag; + +typedef struct { + Tazzzz_Tag tag; + int32_t _0; +} Taz6_Body; + +typedef struct { + Tazzzz_Tag tag; + uint32_t _0; +} Taz7_Body; + +typedef union { + Tazzzz_Tag tag; + Taz6_Body taz6; + Taz7_Body taz7; +} Tazzzz; + +void root(const Foo_u32 *a, + const Baz_i32 *b, + const Taz *c, + Tazz d, + const Tazzz *e, + const Tazzzz *f); diff --git a/tests/expectations/destructor-and-copy-ctor.compat.c b/tests/expectations/destructor-and-copy-ctor.compat.c index 687d35b..15b2e6a 100644 --- a/tests/expectations/destructor-and-copy-ctor.compat.c +++ b/tests/expectations/destructor-and-copy-ctor.compat.c @@ -195,11 +195,66 @@ typedef union { Taz2_Body taz2; } Tazz; +enum Tazzz_Tag +#ifdef __cplusplus + : uint8_t +#endif // __cplusplus + { + Bar5, + Taz5, +}; +#ifndef __cplusplus +typedef uint8_t Tazzz_Tag; +#endif // __cplusplus + +typedef struct { + Tazzz_Tag tag; + int32_t _0; +} Taz5_Body; + +typedef union { + Tazzz_Tag tag; + Taz5_Body taz5; +} Tazzz; + +enum Tazzzz_Tag +#ifdef __cplusplus + : uint8_t +#endif // __cplusplus + { + Taz6, + Taz7, +}; +#ifndef __cplusplus +typedef uint8_t Tazzzz_Tag; +#endif // __cplusplus + +typedef struct { + Tazzzz_Tag tag; + int32_t _0; +} Taz6_Body; + +typedef struct { + Tazzzz_Tag tag; + uint32_t _0; +} Taz7_Body; + +typedef union { + Tazzzz_Tag tag; + Taz6_Body taz6; + Taz7_Body taz7; +} Tazzzz; + #ifdef __cplusplus extern "C" { #endif // __cplusplus -void root(const Foo_u32 *a, const Baz_i32 *b, const Taz *c, Tazz d); +void root(const Foo_u32 *a, + const Baz_i32 *b, + const Taz *c, + Tazz d, + const Tazzz *e, + const Tazzzz *f); #ifdef __cplusplus } // extern "C" diff --git a/tests/expectations/destructor-and-copy-ctor.cpp b/tests/expectations/destructor-and-copy-ctor.cpp index d6a42c4..c9c77b2 100644 --- a/tests/expectations/destructor-and-copy-ctor.cpp +++ b/tests/expectations/destructor-and-copy-ctor.cpp @@ -458,8 +458,149 @@ union Tazz { }; +union Tazzz { + enum class Tag : uint8_t { + Bar5, + Taz5, + }; + + struct Taz5_Body { + Tag tag; + int32_t _0; + }; + + struct { + Tag tag; + }; + Taz5_Body taz5; + + static Tazzz Bar5() { + Tazzz result; + result.tag = Tag::Bar5; + return result; + } + + bool IsBar5() const { + return tag == Tag::Bar5; + } + + static Tazzz Taz5(const int32_t &a0) { + Tazzz result; + ::new (&result.taz5._0) (int32_t)(a0); + result.tag = Tag::Taz5; + return result; + } + + bool IsTaz5() const { + return tag == Tag::Taz5; + } + + private: + Tazzz() { + + } + public: + + + ~Tazzz() { + switch (tag) { + case Tag::Taz5: taz5.~Taz5_Body(); break; + default: break; + } + } + + Tazzz(const Tazzz& other) + : tag(other.tag) { + switch (tag) { + case Tag::Taz5: ::new (&taz5) (Taz5_Body)(other.taz5); break; + default: break; + } + } +}; + +union Tazzzz { + enum class Tag : uint8_t { + Taz6, + Taz7, + }; + + struct Taz6_Body { + Tag tag; + int32_t _0; + }; + + struct Taz7_Body { + Tag tag; + uint32_t _0; + }; + + struct { + Tag tag; + }; + Taz6_Body taz6; + Taz7_Body taz7; + + static Tazzzz Taz6(const int32_t &a0) { + Tazzzz result; + ::new (&result.taz6._0) (int32_t)(a0); + result.tag = Tag::Taz6; + return result; + } + + bool IsTaz6() const { + return tag == Tag::Taz6; + } + + static Tazzzz Taz7(const uint32_t &a0) { + Tazzzz result; + ::new (&result.taz7._0) (uint32_t)(a0); + result.tag = Tag::Taz7; + return result; + } + + bool IsTaz7() const { + return tag == Tag::Taz7; + } + + private: + Tazzzz() { + + } + public: + + + ~Tazzzz() { + switch (tag) { + case Tag::Taz6: taz6.~Taz6_Body(); break; + case Tag::Taz7: taz7.~Taz7_Body(); break; + + } + } + + Tazzzz(const Tazzzz& other) + : tag(other.tag) { + switch (tag) { + case Tag::Taz6: ::new (&taz6) (Taz6_Body)(other.taz6); break; + case Tag::Taz7: ::new (&taz7) (Taz7_Body)(other.taz7); break; + + } + } + Tazzzz& operator=(const Tazzzz& other) { + if (this != &other) { + this->~Tazzzz(); + new (this) Tazzzz(other); + } + return *this; + } +}; + extern "C" { -void root(const Foo *a, const Baz *b, const Taz *c, Tazz d); +void root(const Foo *a, + const Baz *b, + const Taz *c, + Tazz d, + const Tazzz *e, + const Tazzzz *f); } // extern "C" diff --git a/tests/expectations/tag/destructor-and-copy-ctor.c b/tests/expectations/tag/destructor-and-copy-ctor.c index 8b47895..c80682a 100644 --- a/tests/expectations/tag/destructor-and-copy-ctor.c +++ b/tests/expectations/tag/destructor-and-copy-ctor.c @@ -165,4 +165,47 @@ union Tazz { struct Taz2_Body taz2; }; -void root(const struct Foo_u32 *a, const union Baz_i32 *b, const union Taz *c, union Tazz d); +enum Tazzz_Tag { + Bar5, + Taz5, +}; +typedef uint8_t Tazzz_Tag; + +struct Taz5_Body { + Tazzz_Tag tag; + int32_t _0; +}; + +union Tazzz { + Tazzz_Tag tag; + struct Taz5_Body taz5; +}; + +enum Tazzzz_Tag { + Taz6, + Taz7, +}; +typedef uint8_t Tazzzz_Tag; + +struct Taz6_Body { + Tazzzz_Tag tag; + int32_t _0; +}; + +struct Taz7_Body { + Tazzzz_Tag tag; + uint32_t _0; +}; + +union Tazzzz { + Tazzzz_Tag tag; + struct Taz6_Body taz6; + struct Taz7_Body taz7; +}; + +void root(const struct Foo_u32 *a, + const union Baz_i32 *b, + const union Taz *c, + union Tazz d, + const union Tazzz *e, + const union Tazzzz *f); diff --git a/tests/expectations/tag/destructor-and-copy-ctor.compat.c b/tests/expectations/tag/destructor-and-copy-ctor.compat.c index 700b8a1..b28628a 100644 --- a/tests/expectations/tag/destructor-and-copy-ctor.compat.c +++ b/tests/expectations/tag/destructor-and-copy-ctor.compat.c @@ -195,11 +195,66 @@ union Tazz { struct Taz2_Body taz2; }; +enum Tazzz_Tag +#ifdef __cplusplus + : uint8_t +#endif // __cplusplus + { + Bar5, + Taz5, +}; +#ifndef __cplusplus +typedef uint8_t Tazzz_Tag; +#endif // __cplusplus + +struct Taz5_Body { + Tazzz_Tag tag; + int32_t _0; +}; + +union Tazzz { + Tazzz_Tag tag; + struct Taz5_Body taz5; +}; + +enum Tazzzz_Tag +#ifdef __cplusplus + : uint8_t +#endif // __cplusplus + { + Taz6, + Taz7, +}; +#ifndef __cplusplus +typedef uint8_t Tazzzz_Tag; +#endif // __cplusplus + +struct Taz6_Body { + Tazzzz_Tag tag; + int32_t _0; +}; + +struct Taz7_Body { + Tazzzz_Tag tag; + uint32_t _0; +}; + +union Tazzzz { + Tazzzz_Tag tag; + struct Taz6_Body taz6; + struct Taz7_Body taz7; +}; + #ifdef __cplusplus extern "C" { #endif // __cplusplus -void root(const struct Foo_u32 *a, const union Baz_i32 *b, const union Taz *c, union Tazz d); +void root(const struct Foo_u32 *a, + const union Baz_i32 *b, + const union Taz *c, + union Tazz d, + const union Tazzz *e, + const union Tazzzz *f); #ifdef __cplusplus } // extern "C" diff --git a/tests/rust/destructor-and-copy-ctor.rs b/tests/rust/destructor-and-copy-ctor.rs index 24ccf18..30067a7 100644 --- a/tests/rust/destructor-and-copy-ctor.rs +++ b/tests/rust/destructor-and-copy-ctor.rs @@ -66,10 +66,17 @@ pub enum Tazz { /// cbindgen:derive-tagged-enum-copy-assignment=false #[repr(u8)] -pub enum Tazz { - Bar4, - Taz2(i32), +pub enum Tazzz { + Bar5, + Taz5(i32), } +#[repr(u8)] +pub enum Tazzzz { + Taz6(i32), + Taz7(u32), +} + + #[no_mangle] -pub extern "C" fn root(a: &Foo, b: &Baz, c: &Taz, d: Tazz) {} +pub extern "C" fn root(a: &Foo, b: &Baz, c: &Taz, d: Tazz, e: &Tazzz, f: &Tazzzz) {}