Skip to content

Commit 46a7d0b

Browse files
committed
fixup: add fwd decls to test case
- struct with normal fwd decl and blocklisted definition ignored - struct with blocklisted fwd decl and normal definition emitted
1 parent ccd4b82 commit 46a7d0b

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

tests/expectations/tests/blocklist-file.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,34 @@ fn bindgen_test_layout_SizedIntegers() {
6161
)
6262
);
6363
}
64+
#[repr(C)]
65+
#[derive(Debug, Default, Copy, Clone)]
66+
pub struct StructWithBlocklistedFwdDecl {
67+
pub b: u8,
68+
}
69+
#[test]
70+
fn bindgen_test_layout_StructWithBlocklistedFwdDecl() {
71+
assert_eq!(
72+
::std::mem::size_of::<StructWithBlocklistedFwdDecl>(),
73+
1usize,
74+
concat!("Size of: ", stringify!(StructWithBlocklistedFwdDecl))
75+
);
76+
assert_eq!(
77+
::std::mem::align_of::<StructWithBlocklistedFwdDecl>(),
78+
1usize,
79+
concat!("Alignment of ", stringify!(StructWithBlocklistedFwdDecl))
80+
);
81+
assert_eq!(
82+
unsafe {
83+
&(*(::std::ptr::null::<StructWithBlocklistedFwdDecl>())).b
84+
as *const _ as usize
85+
},
86+
0usize,
87+
concat!(
88+
"Offset of field: ",
89+
stringify!(StructWithBlocklistedFwdDecl),
90+
"::",
91+
stringify!(b)
92+
)
93+
);
94+
}

tests/headers/blocklist-file.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// bindgen-flags: --blocklist-file ".*/blocklisted/file.*" -- -Itests/headers
22

3+
// Forward declaration of struct that's defined in a blocklisted file.
4+
struct StructWithBlocklistedDefinition;
5+
36
#include "blocklisted/file.hpp"
47
#include "blocklisted/fake-stdint.h"
58

@@ -8,3 +11,8 @@ struct SizedIntegers {
811
uint16_t y;
912
uint32_t z;
1013
};
14+
15+
// Actual definition of struct that has a forward declaration in a blocklisted file.
16+
struct StructWithBlocklistedFwdDecl {
17+
uint8_t b;
18+
};

tests/headers/blocklisted/file.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ namespace foo {
1717
namespace bar {
1818
void NamespacedFunction();
1919
}
20+
21+
22+
struct StructWithBlocklistedFwdDecl;
23+
24+
struct StructWithBlocklistedDefinition {
25+
StructWithBlocklistedFwdDecl* other;
26+
};

0 commit comments

Comments
 (0)