Skip to content

Commit 9539d3d

Browse files
committed
parser: fix some bugs regarding the copiability of objects
1 parent 774c7da commit 9539d3d

File tree

4 files changed

+63
-7
lines changed

4 files changed

+63
-7
lines changed

src/parser.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,18 @@ fn conv_decl_ty_resolving_typedefs(ctx: &mut ClangParserCtx,
360360
// it's important not to override
361361
if !args.is_empty() {
362362
ci.borrow_mut().args = args;
363+
// XXX: This is a super-dumb way to get the spesialisation,
364+
// but it seems to be the only one that'd work here...
365+
cursor.visit(|c, _: &Cursor| {
366+
if c.kind() == CXCursor_TemplateRef {
367+
let decl = decl_name(ctx, &c.referenced());
368+
ci.borrow_mut().ref_template = Some(decl.to_type());
369+
}
370+
CXChildVisit_Continue
371+
});
363372
}
364373

374+
365375
TComp(ci)
366376
}
367377
CXCursor_EnumDecl => {

src/types.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,6 @@ impl CompInfo {
538538
}
539539
}
540540

541-
// We only
542541
pub fn can_derive_copy(&self) -> bool {
543542
match self.kind {
544543
CompKind::Union => true,
@@ -547,12 +546,6 @@ impl CompInfo {
547546
return false;
548547
}
549548

550-
// Anything not destructible and with template parameters
551-
// is copiable
552-
if self.args.is_empty() {
553-
return true;
554-
}
555-
556549
// With template args, use a safe subset of the types,
557550
// since copyability depends on the types itself.
558551
self.ref_template.as_ref().map_or(true, |t| t.can_derive_copy()) &&

tests/expectations/template.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,33 @@ fn bindgen_test_layout_Struct_RootedContainer() {
4747
assert_eq!(::std::mem::size_of::<Struct_RootedContainer>() , 24usize);
4848
assert_eq!(::std::mem::align_of::<Struct_RootedContainer>() , 8usize);
4949
}
50+
pub type WithDtorIntFwd = Struct_WithDtor<::std::os::raw::c_int>;
51+
#[repr(C)]
52+
#[derive(Debug)]
53+
pub struct Struct_WithDtor<T> {
54+
pub member: T,
55+
}
56+
#[repr(C)]
57+
#[derive(Debug)]
58+
pub struct Struct_PODButContainsDtor {
59+
pub member: WithDtorIntFwd,
60+
}
61+
#[test]
62+
fn bindgen_test_layout_Struct_PODButContainsDtor() {
63+
assert_eq!(::std::mem::size_of::<Struct_PODButContainsDtor>() , 4usize);
64+
assert_eq!(::std::mem::align_of::<Struct_PODButContainsDtor>() , 4usize);
65+
}
66+
#[repr(C)]
67+
pub struct Opaque;
68+
#[repr(C)]
69+
pub struct Struct_POD {
70+
pub opaque_member: u32,
71+
}
72+
#[test]
73+
fn bindgen_test_layout_Struct_POD() {
74+
assert_eq!(::std::mem::size_of::<Struct_POD>() , 4usize);
75+
assert_eq!(::std::mem::align_of::<Struct_POD>() , 4usize);
76+
}
5077
extern "C" {
5178
#[link_name = "_Z3bar3FooIiiE"]
5279
pub fn bar(foo: Struct_Foo<::std::os::raw::c_int, ::std::os::raw::c_int>);

tests/headers/template.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,29 @@ class Rooted {
2929
class RootedContainer {
3030
Rooted<void*> root;
3131
};
32+
33+
template<typename T>
34+
class WithDtor;
35+
36+
typedef WithDtor<int> WithDtorIntFwd;
37+
38+
template<typename T>
39+
class WithDtor {
40+
T member;
41+
~WithDtor() {}
42+
};
43+
44+
class PODButContainsDtor {
45+
WithDtorIntFwd member;
46+
};
47+
48+
49+
/** <div rustbindgen opaque> */
50+
template<typename T>
51+
class Opaque {
52+
T member;
53+
};
54+
55+
class POD {
56+
Opaque<int> opaque_member;
57+
};

0 commit comments

Comments
 (0)