Skip to content

Commit cdc8713

Browse files
committed
Make incomplete array fields copiable.
These aren't extremely great, since this usually requires extra bookkeeping. But C allows it, so let's keep the same semantics.
1 parent 6acbd45 commit cdc8713

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

tests/expectations/tests/class.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ impl <T> ::std::fmt::Debug for __IncompleteArrayField<T> {
3131
fmt.write_str("__IncompleteArrayField")
3232
}
3333
}
34+
impl <T> ::std::clone::Clone for __IncompleteArrayField<T> {
35+
#[inline]
36+
fn clone(&self) -> Self { Self::new() }
37+
}
38+
impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { }
3439
#[repr(C)]
3540
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
3641
impl <T> __BindgenUnionField<T> {
@@ -112,6 +117,16 @@ fn bindgen_test_layout_WithDtor() {
112117
assert_eq!(::std::mem::align_of::<WithDtor>() , 4usize);
113118
}
114119
#[repr(C)]
120+
pub struct IncompleteArrayNonCopiable {
121+
pub whatever: *mut ::std::os::raw::c_void,
122+
pub incomplete_array: __IncompleteArrayField<C>,
123+
}
124+
#[test]
125+
fn bindgen_test_layout_IncompleteArrayNonCopiable() {
126+
assert_eq!(::std::mem::size_of::<IncompleteArrayNonCopiable>() , 8usize);
127+
assert_eq!(::std::mem::align_of::<IncompleteArrayNonCopiable>() , 8usize);
128+
}
129+
#[repr(C)]
115130
#[derive(Debug, Copy)]
116131
pub struct Union {
117132
pub d: __BindgenUnionField<f32>,

tests/headers/class.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class WithDtor {
3232
~WithDtor() {}
3333
};
3434

35+
class IncompleteArrayNonCopiable {
36+
void* whatever;
37+
C incomplete_array[];
38+
};
39+
3540
union Union {
3641
float d;
3742
int i;

0 commit comments

Comments
 (0)