diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/expectations/tests/doggo-or-null.rs | 65 | ||||
-rw-r--r-- | tests/headers/doggo-or-null.hpp | 20 |
2 files changed, 85 insertions, 0 deletions
diff --git a/tests/expectations/tests/doggo-or-null.rs b/tests/expectations/tests/doggo-or-null.rs new file mode 100644 index 00000000..292533d9 --- /dev/null +++ b/tests/expectations/tests/doggo-or-null.rs @@ -0,0 +1,65 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +#[repr(C)] +#[derive(Debug, Default, Copy, Hash, PartialEq)] +pub struct Doggo { + pub x: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_Doggo() { + assert_eq!(::std::mem::size_of::<Doggo>() , 4usize , concat ! ( + "Size of: " , stringify ! ( Doggo ) )); + assert_eq! (::std::mem::align_of::<Doggo>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( Doggo ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const Doggo ) ) . x as * const _ as usize } , + 0usize , concat ! ( + "Alignment of field: " , stringify ! ( Doggo ) , "::" , + stringify ! ( x ) )); +} +impl Clone for Doggo { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Hash, PartialEq)] +pub struct Null { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_Null() { + assert_eq!(::std::mem::size_of::<Null>() , 1usize , concat ! ( + "Size of: " , stringify ! ( Null ) )); + assert_eq! (::std::mem::align_of::<Null>() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Null ) )); +} +impl Clone for Null { + fn clone(&self) -> Self { *self } +} +/// This type is an opaque union. Unions can't derive anything interesting like +/// Debug or Default, even if their layout can, because it would require knowing +/// which variant is in use. Opaque unions still end up as a `union` in the Rust +/// bindings, but they just have one variant. Even so, can't derive. We should +/// probably emit an opaque struct for opaque unions... but until then, we have +/// this test to make sure that opaque unions don't derive and still compile. +#[repr(C)] +#[derive(Copy)] +pub union DoggoOrNull { + pub _bindgen_opaque_blob: u32, +} +#[test] +fn bindgen_test_layout_DoggoOrNull() { + assert_eq!(::std::mem::size_of::<DoggoOrNull>() , 4usize , concat ! ( + "Size of: " , stringify ! ( DoggoOrNull ) )); + assert_eq! (::std::mem::align_of::<DoggoOrNull>() , 4usize , concat ! ( + "Alignment of " , stringify ! ( DoggoOrNull ) )); +} +impl Clone for DoggoOrNull { + fn clone(&self) -> Self { *self } +} +impl Default for DoggoOrNull { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/headers/doggo-or-null.hpp b/tests/headers/doggo-or-null.hpp new file mode 100644 index 00000000..9146e189 --- /dev/null +++ b/tests/headers/doggo-or-null.hpp @@ -0,0 +1,20 @@ +// bindgen-flags: --opaque-type DoggoOrNull --with-derive-partialeq --with-derive-hash -- -std=c++14 + +class Doggo { + int x; +}; + +class Null {}; + +/** + * This type is an opaque union. Unions can't derive anything interesting like + * Debug or Default, even if their layout can, because it would require knowing + * which variant is in use. Opaque unions still end up as a `union` in the Rust + * bindings, but they just have one variant. Even so, can't derive. We should + * probably emit an opaque struct for opaque unions... but until then, we have + * this test to make sure that opaque unions don't derive and still compile. + */ +union DoggoOrNull { + Doggo doggo; + Null none; +}; |