Anon union. I was hoping this would workaround the GCC restriction as the union has no destructor, but it seems it doesn't :(
diff --git a/src/bindgen/ir/enumeration.rs b/src/bindgen/ir/enumeration.rs index 476c2b4..18526717 100644 --- a/src/bindgen/ir/enumeration.rs +++ b/src/bindgen/ir/enumeration.rs
@@ -924,7 +924,22 @@ out.write("struct"); out.open_brace(); } - out.write_vertical_source_list(&body.fields, ListType::Cap(";")); + let mut first = true; + for field in body.fields.iter() { + if !first { + out.new_line(); + } + first = false; + if config.language == Language::Cxx { + out.write("union"); + out.open_brace(); + } + field.write(config, out); + out.write(";"); + if config.language == Language::Cxx { + out.close_brace(true); + } + } if config.language != Language::Cython { out.close_brace(true); }
diff --git a/tests/expectations/annotation.cpp b/tests/expectations/annotation.cpp index 59f6add..c257232 100644 --- a/tests/expectations/annotation.cpp +++ b/tests/expectations/annotation.cpp
@@ -46,8 +46,12 @@ Tag tag; }; struct { - Tag foo_tag; - int16_t foo; + union { + Tag foo_tag; + }; + union { + int16_t foo; + }; }; Bar_Body bar; @@ -101,7 +105,9 @@ Tag tag; union { struct { - int16_t hello; + union { + int16_t hello; + }; }; There_Body there; };
diff --git a/tests/expectations/array.cpp b/tests/expectations/array.cpp index d77972c..c910380 100644 --- a/tests/expectations/array.cpp +++ b/tests/expectations/array.cpp
@@ -12,7 +12,9 @@ Tag tag; union { struct { - float a[20]; + union { + float a[20]; + }; }; };
diff --git a/tests/expectations/asserted_cast.cpp b/tests/expectations/asserted_cast.cpp index 75c8d09..49b17df 100644 --- a/tests/expectations/asserted_cast.cpp +++ b/tests/expectations/asserted_cast.cpp
@@ -25,7 +25,9 @@ Tag tag; union { struct { - int16_t foo; + union { + int16_t foo; + }; }; H_Bar_Body bar; }; @@ -100,7 +102,9 @@ Tag tag; union { struct { - int16_t foo; + union { + int16_t foo; + }; }; J_Bar_Body bar; }; @@ -177,8 +181,12 @@ Tag tag; }; struct { - Tag foo_tag; - int16_t foo; + union { + Tag foo_tag; + }; + union { + int16_t foo; + }; }; K_Bar_Body bar;
diff --git a/tests/expectations/body.cpp b/tests/expectations/body.cpp index ead6176..883178b 100644 --- a/tests/expectations/body.cpp +++ b/tests/expectations/body.cpp
@@ -33,10 +33,14 @@ Tag tag; union { struct { - int32_t bar; + union { + int32_t bar; + }; }; struct { - int32_t baz; + union { + int32_t baz; + }; }; }; #ifdef __cplusplus @@ -70,10 +74,14 @@ Tag tag; union { struct { - int32_t bar_prepended; + union { + int32_t bar_prepended; + }; }; struct { - int32_t baz_prepended; + union { + int32_t baz_prepended; + }; }; }; };
diff --git a/tests/expectations/derive_ostream.cpp b/tests/expectations/derive_ostream.cpp index 5df1337..5131338 100644 --- a/tests/expectations/derive_ostream.cpp +++ b/tests/expectations/derive_ostream.cpp
@@ -90,8 +90,12 @@ Tag tag; }; struct { - Tag foo_tag; - int16_t foo; + union { + Tag foo_tag; + }; + union { + int16_t foo; + }; }; Bar_Body bar; }; @@ -136,7 +140,9 @@ Tag tag; union { struct { - int16_t hello; + union { + int16_t hello; + }; }; There_Body there; };
diff --git a/tests/expectations/destructor_and_copy_ctor.cpp b/tests/expectations/destructor_and_copy_ctor.cpp index 4a4929e..294dcd8 100644 --- a/tests/expectations/destructor_and_copy_ctor.cpp +++ b/tests/expectations/destructor_and_copy_ctor.cpp
@@ -52,13 +52,19 @@ Tag tag; union { struct { - Polygon<T> polygon1; + union { + Polygon<T> polygon1; + }; }; struct { - OwnedSlice<T> slice1; + union { + OwnedSlice<T> slice1; + }; }; struct { - OwnedSlice<int32_t> slice2; + union { + OwnedSlice<int32_t> slice2; + }; }; Slice3_Body slice3; Slice4_Body slice4; @@ -198,16 +204,28 @@ Tag tag; }; struct { - Tag polygon21_tag; - Polygon<T> polygon21; + union { + Tag polygon21_tag; + }; + union { + Polygon<T> polygon21; + }; }; struct { - Tag slice21_tag; - OwnedSlice<T> slice21; + union { + Tag slice21_tag; + }; + union { + OwnedSlice<T> slice21; + }; }; struct { - Tag slice22_tag; - OwnedSlice<int32_t> slice22; + union { + Tag slice22_tag; + }; + union { + OwnedSlice<int32_t> slice22; + }; }; Slice23_Body slice23; Slice24_Body slice24; @@ -339,12 +357,20 @@ Tag tag; }; struct { - Tag taz1_tag; - int32_t taz1; + union { + Tag taz1_tag; + }; + union { + int32_t taz1; + }; }; struct { - Tag taz3_tag; - OwnedSlice<int32_t> taz3; + union { + Tag taz3_tag; + }; + union { + OwnedSlice<int32_t> taz3; + }; }; static Taz Bar3() { @@ -427,8 +453,12 @@ Tag tag; }; struct { - Tag taz2_tag; - int32_t taz2; + union { + Tag taz2_tag; + }; + union { + int32_t taz2; + }; }; static Tazz Bar4() { @@ -470,8 +500,12 @@ Tag tag; }; struct { - Tag taz5_tag; - int32_t taz5; + union { + Tag taz5_tag; + }; + union { + int32_t taz5; + }; }; static Tazzz Bar5() { @@ -531,12 +565,20 @@ Tag tag; }; struct { - Tag taz6_tag; - int32_t taz6; + union { + Tag taz6_tag; + }; + union { + int32_t taz6; + }; }; struct { - Tag taz7_tag; - uint32_t taz7; + union { + Tag taz7_tag; + }; + union { + uint32_t taz7; + }; }; static Tazzzz Taz6(const int32_t &taz6) { @@ -609,12 +651,20 @@ Tag tag; }; struct { - Tag qux1_tag; - int32_t qux1; + union { + Tag qux1_tag; + }; + union { + int32_t qux1; + }; }; struct { - Tag qux2_tag; - uint32_t qux2; + union { + Tag qux2_tag; + }; + union { + uint32_t qux2; + }; }; static Qux Qux1(const int32_t &qux1) {
diff --git a/tests/expectations/enum.cpp b/tests/expectations/enum.cpp index 08d66f6..0a60f01 100644 --- a/tests/expectations/enum.cpp +++ b/tests/expectations/enum.cpp
@@ -96,8 +96,12 @@ Tag tag; }; struct { - Tag foo_tag; - int16_t foo; + union { + Tag foo_tag; + }; + union { + int16_t foo; + }; }; Bar_Body bar; }; @@ -117,7 +121,9 @@ Tag tag; union { struct { - int16_t foo; + union { + int16_t foo; + }; }; H_Bar_Body bar; }; @@ -138,7 +144,9 @@ Tag tag; union { struct { - int16_t foo; + union { + int16_t foo; + }; }; I_Bar_Body bar; }; @@ -159,7 +167,9 @@ Tag tag; union { struct { - uint8_t p0; + union { + uint8_t p0; + }; }; P1_Body p1; };
diff --git a/tests/expectations/enum_self.cpp b/tests/expectations/enum_self.cpp index 5301f2a..579a1cf 100644 --- a/tests/expectations/enum_self.cpp +++ b/tests/expectations/enum_self.cpp
@@ -20,12 +20,20 @@ Tag tag; }; struct { - Tag min_tag; - Foo<Bar> min; + union { + Tag min_tag; + }; + union { + Foo<Bar> min; + }; }; struct { - Tag max_tag; - Foo<Bar> max; + union { + Tag max_tag; + }; + union { + Foo<Bar> max; + }; }; };
diff --git a/tests/expectations/forward_declaration.cpp b/tests/expectations/forward_declaration.cpp index 2e58e47..3ffc4db 100644 --- a/tests/expectations/forward_declaration.cpp +++ b/tests/expectations/forward_declaration.cpp
@@ -29,7 +29,9 @@ Tag tag; union { struct { - StructInfo struct_; + union { + StructInfo struct_; + }; }; }; };
diff --git a/tests/expectations/lifetime_arg.cpp b/tests/expectations/lifetime_arg.cpp index 73e2a0d..b0efeb3 100644 --- a/tests/expectations/lifetime_arg.cpp +++ b/tests/expectations/lifetime_arg.cpp
@@ -17,7 +17,9 @@ Tag tag; union { struct { - const uint8_t *u; + union { + const uint8_t *u; + }; }; }; };
diff --git a/tests/expectations/must_use.cpp b/tests/expectations/must_use.cpp index 1496875..92395a3 100644 --- a/tests/expectations/must_use.cpp +++ b/tests/expectations/must_use.cpp
@@ -19,7 +19,9 @@ Tag tag; union { struct { - T *owned; + union { + T *owned; + }; }; }; };
diff --git a/tests/expectations/prefix.cpp b/tests/expectations/prefix.cpp index 2848ff4..47cbf8b 100644 --- a/tests/expectations/prefix.cpp +++ b/tests/expectations/prefix.cpp
@@ -25,8 +25,12 @@ Tag tag; }; struct { - Tag weight_tag; - float weight; + union { + Tag weight_tag; + }; + union { + float weight; + }; }; };
diff --git a/tests/expectations/reserved.cpp b/tests/expectations/reserved.cpp index 8a0ac55..a908078 100644 --- a/tests/expectations/reserved.cpp +++ b/tests/expectations/reserved.cpp
@@ -39,10 +39,14 @@ Tag tag; union { struct { - double double_; + union { + double double_; + }; }; struct { - float float_; + union { + float float_; + }; }; }; }; @@ -56,10 +60,14 @@ Tag tag; union { struct { - double double_; + union { + double double_; + }; }; struct { - float float_; + union { + float float_; + }; }; }; };
diff --git a/tests/expectations/transform_op.cpp b/tests/expectations/transform_op.cpp index 67c194e..aa1fe6e 100644 --- a/tests/expectations/transform_op.cpp +++ b/tests/expectations/transform_op.cpp
@@ -32,12 +32,20 @@ }; Foo_Body foo; struct { - Tag bar_tag; - T bar; + union { + Tag bar_tag; + }; + union { + T bar; + }; }; struct { - Tag baz_tag; - StylePoint<T> baz; + union { + Tag baz_tag; + }; + union { + StylePoint<T> baz; + }; }; static StyleFoo Foo(const int32_t &x, @@ -138,10 +146,14 @@ union { StyleBar1_Body bar1; struct { - T bar2; + union { + T bar2; + }; }; struct { - StylePoint<T> bar3; + union { + StylePoint<T> bar3; + }; }; }; @@ -236,12 +248,20 @@ Tag tag; }; struct { - Tag baz1_tag; - StyleBar<uint32_t> baz1; + union { + Tag baz1_tag; + }; + union { + StyleBar<uint32_t> baz1; + }; }; struct { - Tag baz2_tag; - StylePoint<int32_t> baz2; + union { + Tag baz2_tag; + }; + union { + StylePoint<int32_t> baz2; + }; }; static StyleBaz Baz1(const StyleBar<uint32_t> &baz1) { @@ -307,10 +327,14 @@ Tag tag; union { struct { - StyleBar<uint32_t> taz1; + union { + StyleBar<uint32_t> taz1; + }; }; struct { - StyleBaz taz2; + union { + StyleBaz taz2; + }; }; };