diff --git a/src/bindgen/ir/enumeration.rs b/src/bindgen/ir/enumeration.rs index 71d0c0eb..960862f1 100644 --- a/src/bindgen/ir/enumeration.rs +++ b/src/bindgen/ir/enumeration.rs @@ -682,7 +682,8 @@ impl Source for Enum { out.open_brace(); } - if config.language == Language::C && !config.style.generate_typedef() { + if config.language == Language::C && !size.is_some() && !config.style.generate_typedef() + { out.write("enum "); } diff --git a/tests/expectations/both/enum.c b/tests/expectations/both/enum.c index 365439e2..0a2a2029 100644 --- a/tests/expectations/both/enum.c +++ b/tests/expectations/both/enum.c @@ -157,6 +157,30 @@ typedef struct I { }; } I; +enum P_Tag { + P0, + P1, +}; +typedef uint8_t P_Tag; + +typedef struct P0_Body { + uint8_t _0; +} P0_Body; + +typedef struct P1_Body { + uint8_t _0; + uint8_t _1; + uint8_t _2; +} P1_Body; + +typedef struct P { + P_Tag tag; + union { + P0_Body p0; + P1_Body p1; + }; +} P; + void root(Opaque *opaque, A a, B b, @@ -172,4 +196,12 @@ void root(Opaque *opaque, L l, M m, N n, - O o); + O o, + P p); + +#include +#include "testing-helpers.h" +static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag"); +static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0"); +static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); +static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); diff --git a/tests/expectations/both/enum.compat.c b/tests/expectations/both/enum.compat.c index f899fd69..5b93c765 100644 --- a/tests/expectations/both/enum.compat.c +++ b/tests/expectations/both/enum.compat.c @@ -217,6 +217,36 @@ typedef struct I { }; } I; +enum P_Tag +#ifdef __cplusplus + : uint8_t +#endif // __cplusplus + { + P0, + P1, +}; +#ifndef __cplusplus +typedef uint8_t P_Tag; +#endif // __cplusplus + +typedef struct P0_Body { + uint8_t _0; +} P0_Body; + +typedef struct P1_Body { + uint8_t _0; + uint8_t _1; + uint8_t _2; +} P1_Body; + +typedef struct P { + P_Tag tag; + union { + P0_Body p0; + P1_Body p1; + }; +} P; + #ifdef __cplusplus extern "C" { #endif // __cplusplus @@ -236,8 +266,16 @@ void root(Opaque *opaque, L l, M m, N n, - O o); + O o, + P p); #ifdef __cplusplus } // extern "C" #endif // __cplusplus + +#include +#include "testing-helpers.h" +static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag"); +static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0"); +static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); +static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); diff --git a/tests/expectations/enum.c b/tests/expectations/enum.c index 48eb9345..2cb8fac0 100644 --- a/tests/expectations/enum.c +++ b/tests/expectations/enum.c @@ -157,6 +157,30 @@ typedef struct { }; } I; +enum P_Tag { + P0, + P1, +}; +typedef uint8_t P_Tag; + +typedef struct { + uint8_t _0; +} P0_Body; + +typedef struct { + uint8_t _0; + uint8_t _1; + uint8_t _2; +} P1_Body; + +typedef struct { + P_Tag tag; + union { + P0_Body p0; + P1_Body p1; + }; +} P; + void root(Opaque *opaque, A a, B b, @@ -172,4 +196,12 @@ void root(Opaque *opaque, L l, M m, N n, - O o); + O o, + P p); + +#include +#include "testing-helpers.h" +static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag"); +static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0"); +static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); +static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); diff --git a/tests/expectations/enum.compat.c b/tests/expectations/enum.compat.c index 2025a258..075f27ee 100644 --- a/tests/expectations/enum.compat.c +++ b/tests/expectations/enum.compat.c @@ -217,6 +217,36 @@ typedef struct { }; } I; +enum P_Tag +#ifdef __cplusplus + : uint8_t +#endif // __cplusplus + { + P0, + P1, +}; +#ifndef __cplusplus +typedef uint8_t P_Tag; +#endif // __cplusplus + +typedef struct { + uint8_t _0; +} P0_Body; + +typedef struct { + uint8_t _0; + uint8_t _1; + uint8_t _2; +} P1_Body; + +typedef struct { + P_Tag tag; + union { + P0_Body p0; + P1_Body p1; + }; +} P; + #ifdef __cplusplus extern "C" { #endif // __cplusplus @@ -236,8 +266,16 @@ void root(Opaque *opaque, L l, M m, N n, - O o); + O o, + P p); #ifdef __cplusplus } // extern "C" #endif // __cplusplus + +#include +#include "testing-helpers.h" +static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag"); +static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0"); +static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); +static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); diff --git a/tests/expectations/enum.cpp b/tests/expectations/enum.cpp index d39fa56e..6a63e6c6 100644 --- a/tests/expectations/enum.cpp +++ b/tests/expectations/enum.cpp @@ -149,6 +149,29 @@ struct I { }; }; +struct P { + enum class Tag : uint8_t { + P0, + P1, + }; + + struct P0_Body { + uint8_t _0; + }; + + struct P1_Body { + uint8_t _0; + uint8_t _1; + uint8_t _2; + }; + + Tag tag; + union { + P0_Body p0; + P1_Body p1; + }; +}; + extern "C" { void root(Opaque *opaque, @@ -166,6 +189,14 @@ void root(Opaque *opaque, L l, M m, N n, - O o); + O o, + P p); } // extern "C" + +#include +#include "testing-helpers.h" +static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag"); +static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0"); +static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); +static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); diff --git a/tests/expectations/tag/annotation.c b/tests/expectations/tag/annotation.c index e567839c..6c75c0f5 100644 --- a/tests/expectations/tag/annotation.c +++ b/tests/expectations/tag/annotation.c @@ -37,7 +37,7 @@ struct Bar_Body { }; union F { - enum F_Tag tag; + F_Tag tag; struct Foo_Body foo; struct Bar_Body bar; }; @@ -59,7 +59,7 @@ struct There_Body { }; struct H { - enum H_Tag tag; + H_Tag tag; union { struct Hello_Body hello; struct There_Body there; diff --git a/tests/expectations/tag/annotation.compat.c b/tests/expectations/tag/annotation.compat.c index 37972665..3741d678 100644 --- a/tests/expectations/tag/annotation.compat.c +++ b/tests/expectations/tag/annotation.compat.c @@ -49,7 +49,7 @@ struct Bar_Body { }; union F { - enum F_Tag tag; + F_Tag tag; struct Foo_Body foo; struct Bar_Body bar; }; @@ -77,7 +77,7 @@ struct There_Body { }; struct H { - enum H_Tag tag; + H_Tag tag; union { struct Hello_Body hello; struct There_Body there; diff --git a/tests/expectations/tag/asserted-cast.c b/tests/expectations/tag/asserted-cast.c index 3d63ca89..5ef7f94c 100644 --- a/tests/expectations/tag/asserted-cast.c +++ b/tests/expectations/tag/asserted-cast.c @@ -25,7 +25,7 @@ struct H_Bar_Body { }; struct H { - enum H_Tag tag; + H_Tag tag; union { struct H_Foo_Body foo; struct H_Bar_Body bar; @@ -49,7 +49,7 @@ struct J_Bar_Body { }; struct J { - enum J_Tag tag; + J_Tag tag; union { struct J_Foo_Body foo; struct J_Bar_Body bar; @@ -75,7 +75,7 @@ struct K_Bar_Body { }; union K { - enum K_Tag tag; + K_Tag tag; struct K_Foo_Body foo; struct K_Bar_Body bar; }; diff --git a/tests/expectations/tag/asserted-cast.compat.c b/tests/expectations/tag/asserted-cast.compat.c index 490054ae..98dccafb 100644 --- a/tests/expectations/tag/asserted-cast.compat.c +++ b/tests/expectations/tag/asserted-cast.compat.c @@ -31,7 +31,7 @@ struct H_Bar_Body { }; struct H { - enum H_Tag tag; + H_Tag tag; union { struct H_Foo_Body foo; struct H_Bar_Body bar; @@ -61,7 +61,7 @@ struct J_Bar_Body { }; struct J { - enum J_Tag tag; + J_Tag tag; union { struct J_Foo_Body foo; struct J_Bar_Body bar; @@ -93,7 +93,7 @@ struct K_Bar_Body { }; union K { - enum K_Tag tag; + K_Tag tag; struct K_Foo_Body foo; struct K_Bar_Body bar; }; diff --git a/tests/expectations/tag/derive-eq.c b/tests/expectations/tag/derive-eq.c index b64b36c2..4de1da99 100644 --- a/tests/expectations/tag/derive-eq.c +++ b/tests/expectations/tag/derive-eq.c @@ -34,7 +34,7 @@ struct FooParen_Body { }; union Bar { - enum Bar_Tag tag; + Bar_Tag tag; struct Bazz_Body bazz; struct FooNamed_Body foo_named; struct FooParen_Body foo_paren; diff --git a/tests/expectations/tag/derive-eq.compat.c b/tests/expectations/tag/derive-eq.compat.c index 25d2b0fc..4e99d1c2 100644 --- a/tests/expectations/tag/derive-eq.compat.c +++ b/tests/expectations/tag/derive-eq.compat.c @@ -40,7 +40,7 @@ struct FooParen_Body { }; union Bar { - enum Bar_Tag tag; + Bar_Tag tag; struct Bazz_Body bazz; struct FooNamed_Body foo_named; struct FooParen_Body foo_paren; diff --git a/tests/expectations/tag/destructor-and-copy-ctor.c b/tests/expectations/tag/destructor-and-copy-ctor.c index b28a3ab3..8b47895d 100644 --- a/tests/expectations/tag/destructor-and-copy-ctor.c +++ b/tests/expectations/tag/destructor-and-copy-ctor.c @@ -65,7 +65,7 @@ struct Slice4_Body_u32 { }; struct Foo_u32 { - enum Foo_u32_Tag tag; + Foo_u32_Tag tag; union { struct Polygon1_Body_u32 polygon1; struct Slice1_Body_u32 slice1; @@ -118,7 +118,7 @@ struct Slice24_Body_i32 { }; union Baz_i32 { - enum Baz_i32_Tag tag; + Baz_i32_Tag tag; struct Polygon21_Body_i32 polygon21; struct Slice21_Body_i32 slice21; struct Slice22_Body_i32 slice22; @@ -144,7 +144,7 @@ struct Taz3_Body { }; union Taz { - enum Taz_Tag tag; + Taz_Tag tag; struct Taz1_Body taz1; struct Taz3_Body taz3; }; @@ -161,7 +161,7 @@ struct Taz2_Body { }; union Tazz { - enum Tazz_Tag tag; + Tazz_Tag tag; struct Taz2_Body taz2; }; diff --git a/tests/expectations/tag/destructor-and-copy-ctor.compat.c b/tests/expectations/tag/destructor-and-copy-ctor.compat.c index 98723845..700b8a1d 100644 --- a/tests/expectations/tag/destructor-and-copy-ctor.compat.c +++ b/tests/expectations/tag/destructor-and-copy-ctor.compat.c @@ -77,7 +77,7 @@ struct Slice4_Body_u32 { }; struct Foo_u32 { - enum Foo_u32_Tag tag; + Foo_u32_Tag tag; union { struct Polygon1_Body_u32 polygon1; struct Slice1_Body_u32 slice1; @@ -136,7 +136,7 @@ struct Slice24_Body_i32 { }; union Baz_i32 { - enum Baz_i32_Tag tag; + Baz_i32_Tag tag; struct Polygon21_Body_i32 polygon21; struct Slice21_Body_i32 slice21; struct Slice22_Body_i32 slice22; @@ -168,7 +168,7 @@ struct Taz3_Body { }; union Taz { - enum Taz_Tag tag; + Taz_Tag tag; struct Taz1_Body taz1; struct Taz3_Body taz3; }; @@ -191,7 +191,7 @@ struct Taz2_Body { }; union Tazz { - enum Tazz_Tag tag; + Tazz_Tag tag; struct Taz2_Body taz2; }; diff --git a/tests/expectations/tag/display_list.c b/tests/expectations/tag/display_list.c index bb843e6c..78f53de3 100644 --- a/tests/expectations/tag/display_list.c +++ b/tests/expectations/tag/display_list.c @@ -37,7 +37,7 @@ struct Image_Body { }; union DisplayItem { - enum DisplayItem_Tag tag; + DisplayItem_Tag tag; struct Fill_Body fill; struct Image_Body image; }; diff --git a/tests/expectations/tag/display_list.compat.c b/tests/expectations/tag/display_list.compat.c index 91318db8..86f91657 100644 --- a/tests/expectations/tag/display_list.compat.c +++ b/tests/expectations/tag/display_list.compat.c @@ -43,7 +43,7 @@ struct Image_Body { }; union DisplayItem { - enum DisplayItem_Tag tag; + DisplayItem_Tag tag; struct Fill_Body fill; struct Image_Body image; }; diff --git a/tests/expectations/tag/enum.c b/tests/expectations/tag/enum.c index d98f505e..03d59f28 100644 --- a/tests/expectations/tag/enum.c +++ b/tests/expectations/tag/enum.c @@ -105,7 +105,7 @@ struct Bar_Body { }; union G { - enum G_Tag tag; + G_Tag tag; struct Foo_Body foo; struct Bar_Body bar; }; @@ -150,13 +150,37 @@ struct I_Bar_Body { }; struct I { - enum I_Tag tag; + I_Tag tag; union { struct I_Foo_Body foo; struct I_Bar_Body bar; }; }; +enum P_Tag { + P0, + P1, +}; +typedef uint8_t P_Tag; + +struct P0_Body { + uint8_t _0; +}; + +struct P1_Body { + uint8_t _0; + uint8_t _1; + uint8_t _2; +}; + +struct P { + P_Tag tag; + union { + struct P0_Body p0; + struct P1_Body p1; + }; +}; + void root(struct Opaque *opaque, A a, B b, @@ -172,4 +196,12 @@ void root(struct Opaque *opaque, enum L l, M m, enum N n, - O o); + O o, + struct P p); + +#include +#include "testing-helpers.h" +static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag"); +static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0"); +static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); +static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); diff --git a/tests/expectations/tag/enum.compat.c b/tests/expectations/tag/enum.compat.c index 7b2e4260..21aafa33 100644 --- a/tests/expectations/tag/enum.compat.c +++ b/tests/expectations/tag/enum.compat.c @@ -159,7 +159,7 @@ struct Bar_Body { }; union G { - enum G_Tag tag; + G_Tag tag; struct Foo_Body foo; struct Bar_Body bar; }; @@ -210,13 +210,43 @@ struct I_Bar_Body { }; struct I { - enum I_Tag tag; + I_Tag tag; union { struct I_Foo_Body foo; struct I_Bar_Body bar; }; }; +enum P_Tag +#ifdef __cplusplus + : uint8_t +#endif // __cplusplus + { + P0, + P1, +}; +#ifndef __cplusplus +typedef uint8_t P_Tag; +#endif // __cplusplus + +struct P0_Body { + uint8_t _0; +}; + +struct P1_Body { + uint8_t _0; + uint8_t _1; + uint8_t _2; +}; + +struct P { + P_Tag tag; + union { + struct P0_Body p0; + struct P1_Body p1; + }; +}; + #ifdef __cplusplus extern "C" { #endif // __cplusplus @@ -236,8 +266,16 @@ void root(struct Opaque *opaque, enum L l, M m, enum N n, - O o); + O o, + struct P p); #ifdef __cplusplus } // extern "C" #endif // __cplusplus + +#include +#include "testing-helpers.h" +static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag"); +static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0"); +static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); +static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); diff --git a/tests/expectations/tag/enum_self.c b/tests/expectations/tag/enum_self.c index bddae4ae..66476f0d 100644 --- a/tests/expectations/tag/enum_self.c +++ b/tests/expectations/tag/enum_self.c @@ -25,7 +25,7 @@ struct Max_Body { }; union Bar { - enum Bar_Tag tag; + Bar_Tag tag; struct Min_Body min; struct Max_Body max; }; diff --git a/tests/expectations/tag/enum_self.compat.c b/tests/expectations/tag/enum_self.compat.c index 608f701e..53bb9ab7 100644 --- a/tests/expectations/tag/enum_self.compat.c +++ b/tests/expectations/tag/enum_self.compat.c @@ -31,7 +31,7 @@ struct Max_Body { }; union Bar { - enum Bar_Tag tag; + Bar_Tag tag; struct Min_Body min; struct Max_Body max; }; diff --git a/tests/expectations/tag/must-use.c b/tests/expectations/tag/must-use.c index 04452231..55df7c49 100644 --- a/tests/expectations/tag/must-use.c +++ b/tests/expectations/tag/must-use.c @@ -19,7 +19,7 @@ struct Owned_Body_i32 { }; struct MaybeOwnedPtr_i32 { - enum MaybeOwnedPtr_i32_Tag tag; + MaybeOwnedPtr_i32_Tag tag; union { struct Owned_Body_i32 owned; }; diff --git a/tests/expectations/tag/must-use.compat.c b/tests/expectations/tag/must-use.compat.c index 69fe2796..9bf8bf05 100644 --- a/tests/expectations/tag/must-use.compat.c +++ b/tests/expectations/tag/must-use.compat.c @@ -25,7 +25,7 @@ struct Owned_Body_i32 { }; struct MaybeOwnedPtr_i32 { - enum MaybeOwnedPtr_i32_Tag tag; + MaybeOwnedPtr_i32_Tag tag; union { struct Owned_Body_i32 owned; }; diff --git a/tests/expectations/tag/prefix.c b/tests/expectations/tag/prefix.c index 6f6d1035..005f062f 100644 --- a/tests/expectations/tag/prefix.c +++ b/tests/expectations/tag/prefix.c @@ -26,7 +26,7 @@ struct PREFIX_Weight_Body { }; union PREFIX_AbsoluteFontWeight { - enum PREFIX_AbsoluteFontWeight_Tag tag; + PREFIX_AbsoluteFontWeight_Tag tag; struct PREFIX_Weight_Body weight; }; diff --git a/tests/expectations/tag/prefix.compat.c b/tests/expectations/tag/prefix.compat.c index a6ad2cec..52069c43 100644 --- a/tests/expectations/tag/prefix.compat.c +++ b/tests/expectations/tag/prefix.compat.c @@ -32,7 +32,7 @@ struct PREFIX_Weight_Body { }; union PREFIX_AbsoluteFontWeight { - enum PREFIX_AbsoluteFontWeight_Tag tag; + PREFIX_AbsoluteFontWeight_Tag tag; struct PREFIX_Weight_Body weight; }; diff --git a/tests/expectations/tag/reserved.c b/tests/expectations/tag/reserved.c index 97cb7103..0e8af58d 100644 --- a/tests/expectations/tag/reserved.c +++ b/tests/expectations/tag/reserved.c @@ -24,7 +24,7 @@ struct D_Body { }; struct C { - enum C_Tag tag; + C_Tag tag; union { struct D_Body d; }; diff --git a/tests/expectations/tag/reserved.compat.c b/tests/expectations/tag/reserved.compat.c index 33033c53..39e4e805 100644 --- a/tests/expectations/tag/reserved.compat.c +++ b/tests/expectations/tag/reserved.compat.c @@ -30,7 +30,7 @@ struct D_Body { }; struct C { - enum C_Tag tag; + C_Tag tag; union { struct D_Body d; }; diff --git a/tests/expectations/tag/sentinel.c b/tests/expectations/tag/sentinel.c index 684eeb3e..8e376e63 100644 --- a/tests/expectations/tag/sentinel.c +++ b/tests/expectations/tag/sentinel.c @@ -47,7 +47,7 @@ struct C_C2_Body { }; union C { - enum C_Tag tag; + C_Tag tag; struct C_C1_Body c1; struct C_C2_Body c2; }; diff --git a/tests/expectations/tag/sentinel.compat.c b/tests/expectations/tag/sentinel.compat.c index 828bbcc4..ae7f94c4 100644 --- a/tests/expectations/tag/sentinel.compat.c +++ b/tests/expectations/tag/sentinel.compat.c @@ -65,7 +65,7 @@ struct C_C2_Body { }; union C { - enum C_Tag tag; + C_Tag tag; struct C_C1_Body c1; struct C_C2_Body c2; }; diff --git a/tests/expectations/tag/transform-op.c b/tests/expectations/tag/transform-op.c index 023f3f21..f738fd3e 100644 --- a/tests/expectations/tag/transform-op.c +++ b/tests/expectations/tag/transform-op.c @@ -39,7 +39,7 @@ struct StyleBaz_Body_i32 { }; union StyleFoo_i32 { - enum StyleFoo_i32_Tag tag; + StyleFoo_i32_Tag tag; struct StyleFoo_Body_i32 foo; struct StyleBar_Body_i32 bar; struct StyleBaz_Body_i32 baz; @@ -130,7 +130,7 @@ struct StyleBaz2_Body { }; union StyleBaz { - enum StyleBaz_Tag tag; + StyleBaz_Tag tag; struct StyleBaz1_Body baz1; struct StyleBaz2_Body baz2; }; @@ -151,7 +151,7 @@ struct StyleTaz2_Body { }; struct StyleTaz { - enum StyleTaz_Tag tag; + StyleTaz_Tag tag; union { struct StyleTaz1_Body taz1; struct StyleTaz2_Body taz2; diff --git a/tests/expectations/tag/transform-op.compat.c b/tests/expectations/tag/transform-op.compat.c index 79ed9c31..eb236c35 100644 --- a/tests/expectations/tag/transform-op.compat.c +++ b/tests/expectations/tag/transform-op.compat.c @@ -45,7 +45,7 @@ struct StyleBaz_Body_i32 { }; union StyleFoo_i32 { - enum StyleFoo_i32_Tag tag; + StyleFoo_i32_Tag tag; struct StyleFoo_Body_i32 foo; struct StyleBar_Body_i32 bar; struct StyleBaz_Body_i32 baz; @@ -142,7 +142,7 @@ struct StyleBaz2_Body { }; union StyleBaz { - enum StyleBaz_Tag tag; + StyleBaz_Tag tag; struct StyleBaz1_Body baz1; struct StyleBaz2_Body baz2; }; @@ -169,7 +169,7 @@ struct StyleTaz2_Body { }; struct StyleTaz { - enum StyleTaz_Tag tag; + StyleTaz_Tag tag; union { struct StyleTaz1_Body taz1; struct StyleTaz2_Body taz2; diff --git a/tests/rust/enum.rs b/tests/rust/enum.rs index c98e5df3..562af880 100644 --- a/tests/rust/enum.rs +++ b/tests/rust/enum.rs @@ -121,6 +121,12 @@ enum O { o4, } +#[repr(C, u8)] +enum P { + P0(u8), + P1(u8, u8, u8), +} + #[no_mangle] pub extern "C" fn root( opaque: *mut Opaque, @@ -139,5 +145,6 @@ pub extern "C" fn root( m: M, n: N, o: O, + p: P, ) { } diff --git a/tests/rust/enum.toml b/tests/rust/enum.toml new file mode 100644 index 00000000..145e4cc9 --- /dev/null +++ b/tests/rust/enum.toml @@ -0,0 +1,8 @@ +trailer = """ +#include +#include "testing-helpers.h" +static_assert(offsetof(CBINDGEN_STRUCT(P), tag) == 0, "unexpected offset for tag"); +static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p0"); +static_assert(offsetof(CBINDGEN_STRUCT(P), p0) == 1, "unexpected offset for p1"); +static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P"); +""" \ No newline at end of file