diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 131851fd7d..8c2be498e9 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -1290,9 +1290,10 @@ impl CompInfo { return CXChildVisit_Continue; } + // Even if this is a definition, we may not be the semantic + // parent, see #1281. let inner = Item::parse(cur, Some(potential_id), ctx) .expect("Inner ClassDecl"); - assert_eq!(ctx.resolve_item(inner).parent_id(), potential_id); let inner = inner.expect_type_id(ctx); diff --git a/tests/expectations/tests/issue-1281.rs b/tests/expectations/tests/issue-1281.rs new file mode 100644 index 0000000000..cfc8ca40c1 --- /dev/null +++ b/tests/expectations/tests/issue-1281.rs @@ -0,0 +1,74 @@ +/* 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, Clone)] +pub struct bar { + pub u: foo, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct foo { + pub foo: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_foo() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).foo as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(foo)) + ); +} +#[test] +fn bindgen_test_layout_bar() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bar)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(u)) + ); +} +pub type bar_t = bar; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct baz { + pub f: foo, +} +#[test] +fn bindgen_test_layout_baz() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(baz)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(baz)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).f as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(baz), "::", stringify!(f)) + ); +} diff --git a/tests/headers/issue-1281.h b/tests/headers/issue-1281.h new file mode 100644 index 0000000000..4a3aaab0e5 --- /dev/null +++ b/tests/headers/issue-1281.h @@ -0,0 +1,11 @@ +struct foo; + +typedef struct bar { + struct foo { + int foo; + } u; +} bar_t; + +struct baz { + struct foo f; +};