diff options
60 files changed, 324 insertions, 74 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index c4e13b26..f877dd58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,19 @@ Released YYYY/MM/DD -------------------------------------------------------------------------------- +# 0.32.1 + +Released 2017/12/18 + +## Fixed + +* When translating C/C++ `enum`s into Rust `enum`s using `rustified_enum` / + `--rustified-enum`, properly add `#[repr(C)]` to the emitted `enum`. [#1183][] + +[#1183]: https://github.com/rust-lang-nursery/rust-bindgen/issues/1183 + +-------------------------------------------------------------------------------- + # 0.32.0 Released 2017/12/08 @@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.32.0" +version = "0.32.1" dependencies = [ "cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -13,7 +13,7 @@ name = "bindgen" readme = "README.md" repository = "https://github.com/rust-lang-nursery/rust-bindgen" documentation = "https://docs.rs/bindgen" -version = "0.32.0" +version = "0.32.1" build = "build.rs" include = [ diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index 7ddb98bd..4ab8373e 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -15,6 +15,10 @@ public: static const int* countdown(); }; +class ITest { + virtual void foo() = 0; +}; + namespace testing { typedef Test TypeAlias; diff --git a/book/src/nocopy.md b/book/src/nocopy.md index 06879ed1..ec21f3ae 100644 --- a/book/src/nocopy.md +++ b/book/src/nocopy.md @@ -6,7 +6,7 @@ Clone)]` to a translated type definition will compile, it still shouldn't do that for reasons it can't know. In these cases, the `nocopy` annotation can be used to prevent bindgen to autoderive the `Copy` and `Clone` traits for a type. -###Library +### Library * [`bindgen::Builder::no_copy`](https://docs.rs/bindgen/0.23.1/bindgen/struct.Builder.html#method.no_copy) diff --git a/csmith-fuzzing/predicate.py b/csmith-fuzzing/predicate.py index 2f561148..3bf452ef 100755 --- a/csmith-fuzzing/predicate.py +++ b/csmith-fuzzing/predicate.py @@ -46,6 +46,11 @@ parser.add_argument( help="An argument string that `bindgen` should be invoked with. By default, all traits are derived. Note that the input header and output bindings file will automatically be provided by this script, and you should not manually specify them.") parser.add_argument( + "--save-temp-files", + action="store_true", + help="Do not delete temporary files.") + +parser.add_argument( "input", type=str, default="input.h", @@ -144,11 +149,12 @@ def main(): exit_code = 2 print("Unexpected exception:", e) - for path in TEMP_FILES: - try: - os.remove(path) - except Exception as e: - print("Unexpected exception:", e) + if not args.save_temp_files: + for path in TEMP_FILES: + try: + os.remove(path) + except Exception as e: + print("Unexpected exception:", e) sys.exit(exit_code) diff --git a/src/clang.rs b/src/clang.rs index 223bfc46..c0c96e5e 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -606,11 +606,16 @@ impl Cursor { unsafe { clang_CXXMethod_isConst(self.x) != 0 } } - /// Is this cursor's referent a member function that is declared `const`? + /// Is this cursor's referent a member function that is virtual? pub fn method_is_virtual(&self) -> bool { unsafe { clang_CXXMethod_isVirtual(self.x) != 0 } } + /// Is this cursor's referent a member function that is pure virtual? + pub fn method_is_pure_virtual(&self) -> bool { + unsafe { clang_CXXMethod_isPureVirtual(self.x) != 0 } + } + /// Is this cursor's referent a struct or class with virtual members? pub fn is_virtual_base(&self) -> bool { unsafe { clang_isVirtualBase(self.x) != 0 } diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index db8fc4dd..15885d57 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -26,7 +26,7 @@ use ir::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault, CanDerivePartialEq, CanDeriveEq, CanDerive}; use ir::dot; use ir::enum_ty::{Enum, EnumVariant, EnumVariantValue}; -use ir::function::{Abi, Function, FunctionSig, Linkage}; +use ir::function::{Abi, Function, FunctionKind, FunctionSig, Linkage}; use ir::int::IntKind; use ir::item::{IsOpaque, Item, ItemCanonicalName, ItemCanonicalPath}; use ir::item_kind::ItemKind; @@ -1878,13 +1878,8 @@ impl CodeGenerator for CompInfo { } if ctx.options().codegen_config.destructors { - if let Some((is_virtual, destructor)) = self.destructor() { - let kind = if is_virtual { - MethodKind::VirtualDestructor - } else { - MethodKind::Destructor - }; - + if let Some((kind, destructor)) = self.destructor() { + debug_assert!(kind.is_destructor()); Method::new(kind, destructor, false).codegen_method( ctx, &mut methods, @@ -1990,9 +1985,9 @@ impl MethodCodegen for Method { match self.kind() { MethodKind::Constructor => cc.constructors, MethodKind::Destructor => cc.destructors, - MethodKind::VirtualDestructor => cc.destructors, + MethodKind::VirtualDestructor { .. } => cc.destructors, MethodKind::Static | MethodKind::Normal | - MethodKind::Virtual => cc.methods, + MethodKind::Virtual { .. } => cc.methods, } }); @@ -2148,7 +2143,10 @@ impl EnumVariation { /// A helper type to construct different enum variations. enum EnumBuilder<'a> { - Rust(quote::Tokens), + Rust { + tokens: quote::Tokens, + emitted_any_variants: bool, + }, Bitfield { canonical_name: &'a str, tokens: quote::Tokens, @@ -2188,7 +2186,10 @@ impl<'a> EnumBuilder<'a> { pub enum #ident }; tokens.append("{"); - EnumBuilder::Rust(tokens) + EnumBuilder::Rust { + tokens, + emitted_any_variants: false, + } } EnumVariation::Consts => { @@ -2229,12 +2230,15 @@ impl<'a> EnumBuilder<'a> { }; match self { - EnumBuilder::Rust(tokens) => { + EnumBuilder::Rust { tokens, emitted_any_variants: _ } => { let name = ctx.rust_ident(variant_name); - EnumBuilder::Rust(quote! { - #tokens - #name = #expr, - }) + EnumBuilder::Rust { + tokens: quote! { + #tokens + #name = #expr, + }, + emitted_any_variants: true, + } } EnumBuilder::Bitfield { .. } => { @@ -2295,9 +2299,12 @@ impl<'a> EnumBuilder<'a> { result: &mut CodegenResult<'b>, ) -> quote::Tokens { match self { - EnumBuilder::Rust(mut t) => { - t.append("}"); - t + EnumBuilder::Rust { mut tokens, emitted_any_variants } => { + if !emitted_any_variants { + tokens.append(quote! { __bindgen_cannot_repr_c_on_empty_enum = 0 }); + } + tokens.append("}"); + tokens } EnumBuilder::Bitfield { canonical_name, @@ -2432,15 +2439,12 @@ impl CodeGenerator for Enum { let mut attrs = vec![]; - // FIXME: Rust forbids repr with empty enums. Remove this condition when - // this is allowed. - // // TODO(emilio): Delegate this to the builders? if variation.is_rust() { - if !self.variants().is_empty() { - attrs.push(attributes::repr(repr_name)); - } - } else if variation.is_bitfield() { + attrs.push(attributes::repr(repr_name)); + } + + if variation.is_bitfield() || variation.is_rust() { attrs.push(attributes::repr("C")); } @@ -3165,6 +3169,15 @@ impl CodeGenerator for Function { Linkage::External => {} } + // Pure virtual methods have no actual symbol, so we can't generate + // something meaningful for them. + match self.kind() { + FunctionKind::Method(ref method_kind) if method_kind.is_pure_virtual() => { + return; + } + _ => {}, + } + // Similar to static member variables in a class template, we can't // generate bindings to template functions, because the set of // instantiations is open ended and we have no way of knowing which diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 58bd3d3c..5008dcfd 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -37,13 +37,40 @@ pub enum MethodKind { /// A destructor. Destructor, /// A virtual destructor. - VirtualDestructor, + VirtualDestructor { + /// Whether it's pure virtual. + pure_virtual: bool, + }, /// A static method. Static, /// A normal method. Normal, /// A virtual method. - Virtual, + Virtual { + /// Whether it's pure virtual. + pure_virtual: bool, + }, +} + + +impl MethodKind { + /// Is this a destructor method? + pub fn is_destructor(&self) -> bool { + match *self { + MethodKind::Destructor | + MethodKind::VirtualDestructor { .. } => true, + _ => false, + } + } + + /// Is this a pure virtual method? + pub fn is_pure_virtual(&self) -> bool { + match *self { + MethodKind::Virtual { pure_virtual } | + MethodKind::VirtualDestructor { pure_virtual } => pure_virtual, + _ => false, + } + } } /// A struct representing a C++ method, either static, normal, or virtual. @@ -73,12 +100,6 @@ impl Method { self.kind } - /// Is this a destructor method? - pub fn is_destructor(&self) -> bool { - self.kind == MethodKind::Destructor || - self.kind == MethodKind::VirtualDestructor - } - /// Is this a constructor? pub fn is_constructor(&self) -> bool { self.kind == MethodKind::Constructor @@ -86,8 +107,11 @@ impl Method { /// Is this a virtual method? pub fn is_virtual(&self) -> bool { - self.kind == MethodKind::Virtual || - self.kind == MethodKind::VirtualDestructor + match self.kind { + MethodKind::Virtual { .. } | + MethodKind::VirtualDestructor { .. } => true, + _ => false, + } } /// Is this a static method? @@ -960,7 +984,7 @@ pub struct CompInfo { /// The destructor of this type. The bool represents whether this destructor /// is virtual. - destructor: Option<(bool, FunctionId)>, + destructor: Option<(MethodKind, FunctionId)>, /// Vector of classes this one inherits from. base_members: Vec<Base>, @@ -1104,7 +1128,7 @@ impl CompInfo { } /// Get this type's destructor. - pub fn destructor(&self) -> Option<(bool, FunctionId)> { + pub fn destructor(&self) -> Option<(MethodKind, FunctionId)> { self.destructor } @@ -1355,14 +1379,23 @@ impl CompInfo { ci.constructors.push(signature); } CXCursor_Destructor => { - ci.destructor = Some((is_virtual, signature)); + let kind = if is_virtual { + MethodKind::VirtualDestructor { + pure_virtual: cur.method_is_pure_virtual(), + } + } else { + MethodKind::Destructor + }; + ci.destructor = Some((kind, signature)); } CXCursor_CXXMethod => { let is_const = cur.method_is_const(); let method_kind = if is_static { MethodKind::Static } else if is_virtual { - MethodKind::Virtual + MethodKind::Virtual { + pure_virtual: cur.method_is_pure_virtual(), + } } else { MethodKind::Normal }; @@ -1658,11 +1691,11 @@ impl Trace for CompInfo { } for method in self.methods() { - if method.is_destructor() { - tracer.visit_kind(method.signature.into(), EdgeKind::Destructor); - } else { - tracer.visit_kind(method.signature.into(), EdgeKind::Method); - } + tracer.visit_kind(method.signature.into(), EdgeKind::Method); + } + + if let Some((_kind, signature)) = self.destructor() { + tracer.visit_kind(signature.into(), EdgeKind::Destructor); } for ctor in self.constructors() { diff --git a/src/ir/function.rs b/src/ir/function.rs index 62792484..7b8349a2 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -27,17 +27,26 @@ pub enum FunctionKind { impl FunctionKind { fn from_cursor(cursor: &clang::Cursor) -> Option<FunctionKind> { + // FIXME(emilio): Deduplicate logic with `ir::comp`. Some(match cursor.kind() { clang_sys::CXCursor_FunctionDecl => FunctionKind::Function, clang_sys::CXCursor_Constructor => FunctionKind::Method( MethodKind::Constructor, ), clang_sys::CXCursor_Destructor => FunctionKind::Method( - MethodKind::Destructor, + if cursor.method_is_virtual() { + MethodKind::VirtualDestructor { + pure_virtual: cursor.method_is_pure_virtual(), + } + } else { + MethodKind::Destructor + } ), clang_sys::CXCursor_CXXMethod => { if cursor.method_is_virtual() { - FunctionKind::Method(MethodKind::Virtual) + FunctionKind::Method(MethodKind::Virtual { + pure_virtual: cursor.method_is_pure_virtual(), + }) } else if cursor.method_is_static() { FunctionKind::Method(MethodKind::Static) } else { diff --git a/src/ir/item.rs b/src/ir/item.rs index a9203639..89ab2569 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -944,12 +944,12 @@ impl Item { cc.constructors } FunctionKind::Method(MethodKind::Destructor) | - FunctionKind::Method(MethodKind::VirtualDestructor) => { + FunctionKind::Method(MethodKind::VirtualDestructor { .. }) => { cc.destructors } FunctionKind::Method(MethodKind::Static) | FunctionKind::Method(MethodKind::Normal) | - FunctionKind::Method(MethodKind::Virtual) => cc.methods, + FunctionKind::Method(MethodKind::Virtual { .. }) => cc.methods, } } } @@ -1711,15 +1711,7 @@ impl Bindings { let rustfmt = which::which("rustfmt") .map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_owned()))?; - // Prefer using the `rustfmt-nightly` version of `rustmft`, if - // possible. It requires being run via `rustup run nightly ...`. - let mut cmd = if let Ok(rustup) = which::which("rustup") { - let mut cmd = Command::new(rustup); - cmd.args(&["run", "nightly", "rustfmt", "--"]); - cmd - } else { - Command::new(rustfmt) - }; + let mut cmd = Command::new(rustfmt); cmd .stdin(Stdio::piped()) diff --git a/tests/expectations/tests/anon_enum.rs b/tests/expectations/tests/anon_enum.rs index 718905d9..c482530c 100644 --- a/tests/expectations/tests/anon_enum.rs +++ b/tests/expectations/tests/anon_enum.rs @@ -12,6 +12,7 @@ pub struct Test { } pub const Test_T_NONE: Test__bindgen_ty_1 = Test__bindgen_ty_1::T_NONE; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Test__bindgen_ty_1 { T_NONE = 0, @@ -40,6 +41,7 @@ fn bindgen_test_layout_Test() { ); } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Baz { Foo = 0, diff --git a/tests/expectations/tests/anon_enum_trait.rs b/tests/expectations/tests/anon_enum_trait.rs index 9f5a6c56..21d22879 100644 --- a/tests/expectations/tests/anon_enum_trait.rs +++ b/tests/expectations/tests/anon_enum_trait.rs @@ -19,6 +19,7 @@ pub const DataType_channels: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::ge pub const DataType_fmt: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; pub const DataType_type_: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum DataType__bindgen_ty_1 { generic_type = 0, @@ -31,6 +32,7 @@ pub struct Foo { pub const Foo_Bar: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar; pub const Foo_Baz: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Foo__bindgen_ty_1 { Bar = 0, diff --git a/tests/expectations/tests/anon_enum_whitelist.rs b/tests/expectations/tests/anon_enum_whitelist.rs index c639410f..45b858fd 100644 --- a/tests/expectations/tests/anon_enum_whitelist.rs +++ b/tests/expectations/tests/anon_enum_whitelist.rs @@ -7,6 +7,7 @@ pub const NODE_FLAG_FOO: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_FOO; pub const NODE_FLAG_BAR: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_BAR; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { NODE_FLAG_FOO = 0, diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs index fdf01a7a..da990ae9 100644 --- a/tests/expectations/tests/anon_union.rs +++ b/tests/expectations/tests/anon_union.rs @@ -14,6 +14,7 @@ pub struct TErrorResult { pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = TErrorResult_UnionState::HasMessage; #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum TErrorResult_UnionState { HasMessage = 0, diff --git a/tests/expectations/tests/anon_union_1_0.rs b/tests/expectations/tests/anon_union_1_0.rs index 8d19c9fc..67a332c0 100644 --- a/tests/expectations/tests/anon_union_1_0.rs +++ b/tests/expectations/tests/anon_union_1_0.rs @@ -58,6 +58,7 @@ pub struct TErrorResult { pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = TErrorResult_UnionState::HasMessage; #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum TErrorResult_UnionState { HasMessage = 0, diff --git a/tests/expectations/tests/bitfield_align_2.rs b/tests/expectations/tests/bitfield_align_2.rs index 6f4a0f69..5174d1aa 100644 --- a/tests/expectations/tests/bitfield_align_2.rs +++ b/tests/expectations/tests/bitfield_align_2.rs @@ -84,6 +84,7 @@ where } } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum MyEnum { ONE = 0, diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index ecdbdf9f..f6560125 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -214,6 +214,7 @@ fn bindgen_test_layout_B() { ); } #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum StepSyntax { Keyword = 0, diff --git a/tests/expectations/tests/class_with_inner_struct_1_0.rs b/tests/expectations/tests/class_with_inner_struct_1_0.rs index 1236950c..e8072362 100644 --- a/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -272,6 +272,7 @@ impl Clone for B { } } #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum StepSyntax { Keyword = 0, diff --git a/tests/expectations/tests/const_enum_unnamed.rs b/tests/expectations/tests/const_enum_unnamed.rs index 539c8916..833f8351 100644 --- a/tests/expectations/tests/const_enum_unnamed.rs +++ b/tests/expectations/tests/const_enum_unnamed.rs @@ -7,6 +7,7 @@ pub const FOO_BAR: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAR; pub const FOO_BAZ: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAZ; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { FOO_BAR = 0, @@ -19,6 +20,7 @@ pub struct Foo { } pub const Foo_FOO_BAR: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::FOO_BAR; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Foo__bindgen_ty_1 { FOO_BAR = 10, diff --git a/tests/expectations/tests/constify-enum.rs b/tests/expectations/tests/constify-enum.rs index 78644ae4..79fc4dff 100644 --- a/tests/expectations/tests/constify-enum.rs +++ b/tests/expectations/tests/constify-enum.rs @@ -9,6 +9,7 @@ pub const nsCSSPropertyID_eCSSProperty_COUNT_unexistingVariantValue: nsCSSProper pub const nsCSSPropertyID_eCSSProperty_COUNT: nsCSSPropertyID = nsCSSPropertyID::eCSSPropertyAlias_aa; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum nsCSSPropertyID { eCSSProperty_a = 0, diff --git a/tests/expectations/tests/empty-enum.rs b/tests/expectations/tests/empty-enum.rs new file mode 100644 index 00000000..4ec7df8a --- /dev/null +++ b/tests/expectations/tests/empty-enum.rs @@ -0,0 +1,36 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +pub type EmptyConstified = ::std::os::raw::c_uint; +#[repr(u32)] +#[repr(C)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum EmptyRustified { + __bindgen_cannot_repr_c_on_empty_enum = 0, +} +pub mod EmptyModule { + pub type Type = ::std::os::raw::c_uint; +} +#[repr(i8)] +#[repr(C)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum EmptyClassRustified { + __bindgen_cannot_repr_c_on_empty_enum = 0, +} +pub type EmptyClassConstified = ::std::os::raw::c_char; +pub mod EmptyClassModule { + pub type Type = ::std::os::raw::c_char; +} +#[repr(i8)] +#[repr(C)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum ForwardClassRustified { + __bindgen_cannot_repr_c_on_empty_enum = 0, +} +pub type ForwardClassConstified = ::std::os::raw::c_char; +pub mod ForwardClassModule { + pub type Type = ::std::os::raw::c_char; +} diff --git a/tests/expectations/tests/enum.rs b/tests/expectations/tests/enum.rs index 70c30830..b1920aae 100644 --- a/tests/expectations/tests/enum.rs +++ b/tests/expectations/tests/enum.rs @@ -5,12 +5,14 @@ #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Foo { Bar = 0, Qux = 1, } #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Neg { MinusOne = -1, diff --git a/tests/expectations/tests/enum_alias.rs b/tests/expectations/tests/enum_alias.rs index f12c08d3..cde429f7 100644 --- a/tests/expectations/tests/enum_alias.rs +++ b/tests/expectations/tests/enum_alias.rs @@ -5,6 +5,7 @@ #[repr(u8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Bar { VAL = 0, diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index e9e6f13c..42ee3832 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -7,6 +7,7 @@ pub const match_: _bindgen_ty_1 = _bindgen_ty_1::match_; pub const whatever_else: _bindgen_ty_1 = _bindgen_ty_1::whatever_else; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { match_ = 0, diff --git a/tests/expectations/tests/enum_dupe.rs b/tests/expectations/tests/enum_dupe.rs index a91999ed..151b2cd0 100644 --- a/tests/expectations/tests/enum_dupe.rs +++ b/tests/expectations/tests/enum_dupe.rs @@ -6,6 +6,7 @@ pub const Foo_Dupe: Foo = Foo::Bar; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Foo { Bar = 1, diff --git a/tests/expectations/tests/enum_explicit_type.rs b/tests/expectations/tests/enum_explicit_type.rs index 7ff0ef51..644a1cea 100644 --- a/tests/expectations/tests/enum_explicit_type.rs +++ b/tests/expectations/tests/enum_explicit_type.rs @@ -5,34 +5,40 @@ #[repr(u8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Foo { Bar = 0, Qux = 1, } #[repr(i8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Neg { MinusOne = -1, One = 1, } #[repr(u16)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Bigger { Much = 255, Larger = 256, } #[repr(i64)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum MuchLong { MuchLow = -4294967296, } #[repr(i64)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum MuchLongLong { I64_MIN = -9223372036854775808, } #[repr(u64)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum MuchULongLong { MuchHigh = 4294967296, diff --git a/tests/expectations/tests/enum_in_template_with_typedef.rs b/tests/expectations/tests/enum_in_template_with_typedef.rs index 06dea126..588bb42b 100644 --- a/tests/expectations/tests/enum_in_template_with_typedef.rs +++ b/tests/expectations/tests/enum_in_template_with_typedef.rs @@ -13,6 +13,7 @@ pub type std_fbstring_core_category_type = u8; pub const std_fbstring_core_Category_Bar: std_fbstring_core_Category = std_fbstring_core_Category::Foo; #[repr(u8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum std_fbstring_core_Category { Foo = 0, diff --git a/tests/expectations/tests/enum_negative.rs b/tests/expectations/tests/enum_negative.rs index 100f27db..1fe2f6a4 100644 --- a/tests/expectations/tests/enum_negative.rs +++ b/tests/expectations/tests/enum_negative.rs @@ -5,6 +5,7 @@ #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Foo { Bar = -2, diff --git a/tests/expectations/tests/enum_packed.rs b/tests/expectations/tests/enum_packed.rs index cc85b553..d8e96b0f 100644 --- a/tests/expectations/tests/enum_packed.rs +++ b/tests/expectations/tests/enum_packed.rs @@ -5,18 +5,21 @@ #[repr(u8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Foo { Bar = 0, Qux = 1, } #[repr(i8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Neg { MinusOne = -1, One = 1, } #[repr(u16)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Bigger { Much = 255, diff --git a/tests/expectations/tests/forward-enum-decl.rs b/tests/expectations/tests/forward-enum-decl.rs index 5502c4c4..c2dea97a 100644 --- a/tests/expectations/tests/forward-enum-decl.rs +++ b/tests/expectations/tests/forward-enum-decl.rs @@ -5,6 +5,7 @@ #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum CSSPseudoClassType { empty = 0, diff --git a/tests/expectations/tests/func_ptr_in_struct.rs b/tests/expectations/tests/func_ptr_in_struct.rs index 290a148c..33d908e2 100644 --- a/tests/expectations/tests/func_ptr_in_struct.rs +++ b/tests/expectations/tests/func_ptr_in_struct.rs @@ -4,8 +4,12 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum baz {} +pub enum baz { + __bindgen_cannot_repr_c_on_empty_enum = 0, +} #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo { diff --git a/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs b/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs new file mode 100644 index 00000000..a3c5f4f6 --- /dev/null +++ b/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs @@ -0,0 +1,29 @@ +/* automatically generated by rust-bindgen */ + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + +#[repr(C)] +pub struct Foo__bindgen_vtable(::std::os::raw::c_void); +#[repr(C)] +#[derive(Debug)] +pub struct Foo { + pub vtable_: *const Foo__bindgen_vtable, +} +#[test] +fn bindgen_test_layout_Foo() { + assert_eq!( + ::std::mem::size_of::<Foo>(), + 8usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::<Foo>(), + 8usize, + concat!("Alignment of ", stringify!(Foo)) + ); +} +impl Default for Foo { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} diff --git a/tests/expectations/tests/issue-372.rs b/tests/expectations/tests/issue-372.rs index b2949da3..f9040a99 100644 --- a/tests/expectations/tests/issue-372.rs +++ b/tests/expectations/tests/issue-372.rs @@ -77,6 +77,7 @@ pub mod root { } } #[repr(u32)] + #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum n { o = 0, diff --git a/tests/expectations/tests/issue-410.rs b/tests/expectations/tests/issue-410.rs index 928701ef..f23462bf 100644 --- a/tests/expectations/tests/issue-410.rs +++ b/tests/expectations/tests/issue-410.rs @@ -40,6 +40,10 @@ pub mod root { } } } + #[repr(u32)] + #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] - pub enum JSWhyMagic {} + pub enum JSWhyMagic { + __bindgen_cannot_repr_c_on_empty_enum = 0, + } } diff --git a/tests/expectations/tests/issue-493.rs b/tests/expectations/tests/issue-493.rs index 8975938d..d338e30c 100644 --- a/tests/expectations/tests/issue-493.rs +++ b/tests/expectations/tests/issue-493.rs @@ -70,6 +70,7 @@ impl Default for basic_string___long { pub const basic_string___min_cap: basic_string__bindgen_ty_1 = basic_string__bindgen_ty_1::__min_cap; #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum basic_string__bindgen_ty_1 { __min_cap = 0, @@ -109,6 +110,7 @@ impl Default for basic_string___ulx { pub const basic_string___n_words: basic_string__bindgen_ty_2 = basic_string__bindgen_ty_2::__n_words; #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum basic_string__bindgen_ty_2 { __n_words = 0, diff --git a/tests/expectations/tests/issue-493_1_0.rs b/tests/expectations/tests/issue-493_1_0.rs index da6dac77..4dfc26d8 100644 --- a/tests/expectations/tests/issue-493_1_0.rs +++ b/tests/expectations/tests/issue-493_1_0.rs @@ -70,6 +70,7 @@ impl Default for basic_string___long { pub const basic_string___min_cap: basic_string__bindgen_ty_1 = basic_string__bindgen_ty_1::__min_cap; #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum basic_string__bindgen_ty_1 { __min_cap = 0, @@ -107,6 +108,7 @@ impl Default for basic_string___ulx { pub const basic_string___n_words: basic_string__bindgen_ty_2 = basic_string__bindgen_ty_2::__n_words; #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum basic_string__bindgen_ty_2 { __n_words = 0, diff --git a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs index b2ddf713..3029a670 100644 --- a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs +++ b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs @@ -7,6 +7,7 @@ pub const ENUM_VARIANT_1: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_1; pub const ENUM_VARIANT_2: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_2; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { ENUM_VARIANT_1 = 0, diff --git a/tests/expectations/tests/issue-888-enum-var-decl-jump.rs b/tests/expectations/tests/issue-888-enum-var-decl-jump.rs index 61cbfc3a..c0ac112d 100644 --- a/tests/expectations/tests/issue-888-enum-var-decl-jump.rs +++ b/tests/expectations/tests/issue-888-enum-var-decl-jump.rs @@ -34,6 +34,10 @@ pub mod root { ); } } + #[repr(u32)] + #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] - pub enum a {} + pub enum a { + __bindgen_cannot_repr_c_on_empty_enum = 0, + } } diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index 80526b3e..2b2d0d77 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -87,6 +87,7 @@ pub const JSVAL_TAG_SHIFT: ::std::os::raw::c_uint = 47; pub const JSVAL_PAYLOAD_MASK: ::std::os::raw::c_ulonglong = 140737488355327; pub const JSVAL_TAG_MASK: ::std::os::raw::c_longlong = -140737488355328; #[repr(u8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSValueType { JSVAL_TYPE_DOUBLE = 0, @@ -102,6 +103,7 @@ pub enum JSValueType { JSVAL_TYPE_MISSING = 33, } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSValueTag { JSVAL_TAG_MAX_DOUBLE = 131056, @@ -115,6 +117,7 @@ pub enum JSValueTag { JSVAL_TAG_OBJECT = 131064, } #[repr(u64)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_MAX_DOUBLE = 18444492278190833663, @@ -128,6 +131,7 @@ pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_OBJECT = 18445618173802708992, } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSWhyMagic { JS_ELEMENTS_HOLE = 0, diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs index cac9b0b8..ab11a231 100644 --- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -130,6 +130,7 @@ pub const JSVAL_TAG_SHIFT: ::std::os::raw::c_uint = 47; pub const JSVAL_PAYLOAD_MASK: ::std::os::raw::c_ulonglong = 140737488355327; pub const JSVAL_TAG_MASK: ::std::os::raw::c_longlong = -140737488355328; #[repr(u8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSValueType { JSVAL_TYPE_DOUBLE = 0, @@ -145,6 +146,7 @@ pub enum JSValueType { JSVAL_TYPE_MISSING = 33, } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSValueTag { JSVAL_TAG_MAX_DOUBLE = 131056, @@ -158,6 +160,7 @@ pub enum JSValueTag { JSVAL_TAG_OBJECT = 131064, } #[repr(u64)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_MAX_DOUBLE = 18444492278190833663, @@ -171,6 +174,7 @@ pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_OBJECT = 18445618173802708992, } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSWhyMagic { JS_ELEMENTS_HOLE = 0, diff --git a/tests/expectations/tests/layout_array_too_long.rs b/tests/expectations/tests/layout_array_too_long.rs index b7677573..59884451 100644 --- a/tests/expectations/tests/layout_array_too_long.rs +++ b/tests/expectations/tests/layout_array_too_long.rs @@ -11,6 +11,7 @@ pub const IP_FIRST_FRAG_IDX: _bindgen_ty_1 = _bindgen_ty_1::IP_FIRST_FRAG_IDX; pub const IP_MIN_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MIN_FRAG_NUM; pub const IP_MAX_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MAX_FRAG_NUM; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { IP_LAST_FRAG_IDX = 0, diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/tests/expectations/tests/layout_cmdline_token.rs index 91157416..2cde7c42 100644 --- a/tests/expectations/tests/layout_cmdline_token.rs +++ b/tests/expectations/tests/layout_cmdline_token.rs @@ -83,8 +83,7 @@ pub struct cmdline_token_ops { >, /// return the num of possible choices for this token pub complete_get_nb: ::std::option::Option< - unsafe extern "C" fn(arg1: *mut cmdline_parse_token_hdr_t) - -> ::std::os::raw::c_int, + unsafe extern "C" fn(arg1: *mut cmdline_parse_token_hdr_t) -> ::std::os::raw::c_int, >, /// return the elt x for this token (token, idx, dstbuf, size) pub complete_get_elt: ::std::option::Option< @@ -167,6 +166,7 @@ impl Default for cmdline_token_ops { } } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum cmdline_numtype { UINT8 = 0, diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index 9721fb7b..599f9788 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -116,6 +116,7 @@ pub const RTE_ETH_FLOW_GENEVE: ::std::os::raw::c_uint = 20; pub const RTE_ETH_FLOW_NVGRE: ::std::os::raw::c_uint = 21; pub const RTE_ETH_FLOW_MAX: ::std::os::raw::c_uint = 22; #[repr(u32)] +#[repr(C)] /// A set of values to identify what method is to be used to route /// packets to multiple queues. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -343,6 +344,7 @@ impl rte_eth_rxmode { } } #[repr(u32)] +#[repr(C)] /// A set of values to identify what method is to be used to transmit /// packets using multi-TCs. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -532,6 +534,7 @@ impl Default for rte_eth_rss_conf { } } #[repr(u32)] +#[repr(C)] /// This enum indicates the possible number of traffic classes /// in DCB configratioins #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -540,6 +543,7 @@ pub enum rte_eth_nb_tcs { ETH_8_TCS = 8, } #[repr(u32)] +#[repr(C)] /// This enum indicates the possible number of queue pools /// in VMDQ configurations. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -1054,6 +1058,7 @@ impl Default for rte_eth_vmdq_rx_conf { } } #[repr(u32)] +#[repr(C)] /// Flow Director setting modes: none, signature or perfect. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_fdir_mode { @@ -1064,6 +1069,7 @@ pub enum rte_fdir_mode { RTE_FDIR_MODE_PERFECT_TUNNEL = 4, } #[repr(u32)] +#[repr(C)] /// Memory space that can be configured to store Flow Director filters /// in the board memory. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -1073,6 +1079,7 @@ pub enum rte_fdir_pballoc_type { RTE_FDIR_PBALLOC_256K = 2, } #[repr(u32)] +#[repr(C)] /// Select report mode of FDIR hash information in RX descriptors. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_fdir_status_mode { @@ -1366,6 +1373,7 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); } #[repr(u32)] +#[repr(C)] /// Payload type #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_eth_payload_type { diff --git a/tests/expectations/tests/layout_eth_conf_1_0.rs b/tests/expectations/tests/layout_eth_conf_1_0.rs index ad37574d..532fcae8 100644 --- a/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -159,6 +159,7 @@ pub const RTE_ETH_FLOW_GENEVE: ::std::os::raw::c_uint = 20; pub const RTE_ETH_FLOW_NVGRE: ::std::os::raw::c_uint = 21; pub const RTE_ETH_FLOW_MAX: ::std::os::raw::c_uint = 22; #[repr(u32)] +#[repr(C)] /// A set of values to identify what method is to be used to route /// packets to multiple queues. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -391,6 +392,7 @@ impl rte_eth_rxmode { } } #[repr(u32)] +#[repr(C)] /// A set of values to identify what method is to be used to transmit /// packets using multi-TCs. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -590,6 +592,7 @@ impl Default for rte_eth_rss_conf { } } #[repr(u32)] +#[repr(C)] /// This enum indicates the possible number of traffic classes /// in DCB configratioins #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -598,6 +601,7 @@ pub enum rte_eth_nb_tcs { ETH_8_TCS = 8, } #[repr(u32)] +#[repr(C)] /// This enum indicates the possible number of queue pools /// in VMDQ configurations. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -1152,6 +1156,7 @@ impl Default for rte_eth_vmdq_rx_conf { } } #[repr(u32)] +#[repr(C)] /// Flow Director setting modes: none, signature or perfect. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_fdir_mode { @@ -1162,6 +1167,7 @@ pub enum rte_fdir_mode { RTE_FDIR_MODE_PERFECT_TUNNEL = 4, } #[repr(u32)] +#[repr(C)] /// Memory space that can be configured to store Flow Director filters /// in the board memory. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -1171,6 +1177,7 @@ pub enum rte_fdir_pballoc_type { RTE_FDIR_PBALLOC_256K = 2, } #[repr(u32)] +#[repr(C)] /// Select report mode of FDIR hash information in RX descriptors. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_fdir_status_mode { @@ -1479,6 +1486,7 @@ impl Clone for rte_eth_fdir_masks { } } #[repr(u32)] +#[repr(C)] /// Payload type #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rte_eth_payload_type { diff --git a/tests/expectations/tests/layout_large_align_field.rs b/tests/expectations/tests/layout_large_align_field.rs index 21f84546..501e1bce 100644 --- a/tests/expectations/tests/layout_large_align_field.rs +++ b/tests/expectations/tests/layout_large_align_field.rs @@ -48,6 +48,7 @@ pub const IP_FIRST_FRAG_IDX: _bindgen_ty_1 = _bindgen_ty_1::IP_FIRST_FRAG_IDX; pub const IP_MIN_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MIN_FRAG_NUM; pub const IP_MAX_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MAX_FRAG_NUM; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { IP_LAST_FRAG_IDX = 0, diff --git a/tests/expectations/tests/libclang-3.8/constant-evaluate.rs b/tests/expectations/tests/libclang-3.8/constant-evaluate.rs index 8faddfe9..1b6aca15 100644 --- a/tests/expectations/tests/libclang-3.8/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-3.8/constant-evaluate.rs @@ -7,6 +7,7 @@ pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { foo = 4, bar = 8, } pub type EasyToOverflow = ::std::os::raw::c_ulonglong; diff --git a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs index 096bc182..76cbf24e 100644 --- a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs @@ -7,6 +7,7 @@ pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { foo = 4, diff --git a/tests/expectations/tests/libclang-4/constant-evaluate.rs b/tests/expectations/tests/libclang-4/constant-evaluate.rs index 096bc182..76cbf24e 100644 --- a/tests/expectations/tests/libclang-4/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-4/constant-evaluate.rs @@ -7,6 +7,7 @@ pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_1 { foo = 4, diff --git a/tests/expectations/tests/nsStyleAutoArray.rs b/tests/expectations/tests/nsStyleAutoArray.rs index 0c9f1ec6..199222ec 100644 --- a/tests/expectations/tests/nsStyleAutoArray.rs +++ b/tests/expectations/tests/nsStyleAutoArray.rs @@ -23,6 +23,7 @@ pub struct nsStyleAutoArray<T> { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>, } #[repr(i32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum nsStyleAutoArray_WithSingleInitialElement { WITH_SINGLE_INITIAL_ELEMENT = 0, diff --git a/tests/expectations/tests/overflowed_enum.rs b/tests/expectations/tests/overflowed_enum.rs index 0e8700dc..9104867d 100644 --- a/tests/expectations/tests/overflowed_enum.rs +++ b/tests/expectations/tests/overflowed_enum.rs @@ -5,6 +5,7 @@ #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Foo { BAP_ARM = 9698489, @@ -12,6 +13,7 @@ pub enum Foo { BAP_X86_64 = 3128633167, } #[repr(u16)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Bar { One = 1, diff --git a/tests/expectations/tests/prepend-enum-constified-variant.rs b/tests/expectations/tests/prepend-enum-constified-variant.rs index df9ecf3c..afe2c0b1 100644 --- a/tests/expectations/tests/prepend-enum-constified-variant.rs +++ b/tests/expectations/tests/prepend-enum-constified-variant.rs @@ -6,6 +6,7 @@ pub const AV_CODEC_ID_TTF: AVCodecID = AVCodecID::AV_CODEC_ID_FIRST_UNKNOWN; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum AVCodecID { AV_CODEC_ID_FIRST_UNKNOWN = 98304, diff --git a/tests/expectations/tests/short-enums.rs b/tests/expectations/tests/short-enums.rs index c3b26da9..882b368c 100644 --- a/tests/expectations/tests/short-enums.rs +++ b/tests/expectations/tests/short-enums.rs @@ -5,16 +5,19 @@ #[repr(u8)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum one_byte_t { SOME_VALUE = 1, } #[repr(u16)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum two_byte_t { SOME_OTHER_VALUE = 256, } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum four_byte_t { SOME_BIGGER_VALUE = 16777216, diff --git a/tests/expectations/tests/struct_typedef.rs b/tests/expectations/tests/struct_typedef.rs index d153aa08..0e615144 100644 --- a/tests/expectations/tests/struct_typedef.rs +++ b/tests/expectations/tests/struct_typedef.rs @@ -68,12 +68,14 @@ impl Default for _bindgen_ty_1 { pub type struct_ptr_t = *mut _bindgen_ty_1; pub type struct_ptr_ptr_t = *mut *mut _bindgen_ty_1; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum typedef_named_enum { ENUM_HAS_NAME = 1, } pub const ENUM_IS_ANON: _bindgen_ty_2 = _bindgen_ty_2::ENUM_IS_ANON; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_2 { ENUM_IS_ANON = 0, diff --git a/tests/expectations/tests/struct_typedef_ns.rs b/tests/expectations/tests/struct_typedef_ns.rs index 42dfbb52..cbbdaa7b 100644 --- a/tests/expectations/tests/struct_typedef_ns.rs +++ b/tests/expectations/tests/struct_typedef_ns.rs @@ -40,6 +40,7 @@ pub mod root { ); } #[repr(u32)] + #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum typedef_enum { BAR = 1, @@ -80,6 +81,7 @@ pub mod root { pub const _bindgen_mod_id_12_BAR: root::_bindgen_mod_id_12::_bindgen_ty_2 = _bindgen_ty_2::BAR; #[repr(u32)] + #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum _bindgen_ty_2 { BAR = 1, diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs index 6a4d0589..22cd8ea5 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -84,6 +84,7 @@ where } } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum nsStyleSVGOpacitySource { eStyleSVGOpacitySource_Normal = 0, diff --git a/tests/headers/empty-enum.h b/tests/headers/empty-enum.h new file mode 100644 index 00000000..8b7502e6 --- /dev/null +++ b/tests/headers/empty-enum.h @@ -0,0 +1,15 @@ +// bindgen-flags: --rustified-enum '.*Rustified.*' --constified-enum-module '.*Module.*' -- -x c++ --std=c++14 + +// Constified is default, so no flag for that. + +enum EmptyConstified {}; +enum EmptyRustified {}; +enum EmptyModule {}; + +enum class EmptyClassRustified : char {}; +enum class EmptyClassConstified : char {}; +enum class EmptyClassModule : char {}; + +enum class ForwardClassRustified : char; +enum class ForwardClassConstified : char; +enum class ForwardClassModule : char; diff --git a/tests/headers/issue-1197-pure-virtual-stuff.hpp b/tests/headers/issue-1197-pure-virtual-stuff.hpp new file mode 100644 index 00000000..a0da90c9 --- /dev/null +++ b/tests/headers/issue-1197-pure-virtual-stuff.hpp @@ -0,0 +1,6 @@ +class Foo +{ +public: + virtual void Bar() = 0; + virtual ~Foo() = 0; +}; diff --git a/tests/headers/ref_argument_array.hpp b/tests/headers/ref_argument_array.hpp index dc73fd62..53f66950 100644 --- a/tests/headers/ref_argument_array.hpp +++ b/tests/headers/ref_argument_array.hpp @@ -2,5 +2,5 @@ #define NSID_LENGTH 10 class nsID { public: - virtual void ToProvidedString(char (&aDest)[NSID_LENGTH]) = 0; + virtual void ToProvidedString(char (&aDest)[NSID_LENGTH]); }; |