Skip to content

Commit b60339e

Browse files
authored
Identify forward declarations in params. (#2052)
1 parent e6684dc commit b60339e

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

Diff for: src/clang.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl Cursor {
241241
self.x.kind
242242
}
243243

244-
/// Returns true is the cursor is a definition
244+
/// Returns true if the cursor is a definition
245245
pub fn is_definition(&self) -> bool {
246246
unsafe { clang_isCursorDefinition(self.x) != 0 }
247247
}

Diff for: src/ir/comp.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,7 @@ impl CompInfo {
12491249
let mut ci = CompInfo::new(kind);
12501250
ci.is_forward_declaration =
12511251
location.map_or(true, |cur| match cur.kind() {
1252+
CXCursor_ParmDecl => true,
12521253
CXCursor_StructDecl | CXCursor_UnionDecl |
12531254
CXCursor_ClassDecl => !cur.is_definition(),
12541255
_ => false,

Diff for: tests/expectations/tests/parm-union.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#![allow(
2+
dead_code,
3+
non_snake_case,
4+
non_camel_case_types,
5+
non_upper_case_globals
6+
)]
7+
8+
#[repr(C)]
9+
#[derive(Debug, Default, Copy, Clone)]
10+
pub struct Struct {
11+
pub _address: u8,
12+
}
13+
#[test]
14+
fn bindgen_test_layout_Struct() {
15+
assert_eq!(
16+
::std::mem::size_of::<Struct>(),
17+
1usize,
18+
concat!("Size of: ", stringify!(Struct))
19+
);
20+
assert_eq!(
21+
::std::mem::align_of::<Struct>(),
22+
1usize,
23+
concat!("Alignment of ", stringify!(Struct))
24+
);
25+
}
26+
extern "C" {
27+
#[link_name = "\u{1}_ZN6Struct8FunctionER5Union"]
28+
pub fn Struct_Function(this: *mut Struct, arg1: *mut Union);
29+
}
30+
impl Struct {
31+
#[inline]
32+
pub unsafe fn Function(&mut self, arg1: *mut Union) {
33+
Struct_Function(self, arg1)
34+
}
35+
}
36+
#[repr(C)]
37+
#[derive(Copy, Clone)]
38+
pub struct Union {
39+
_unused: [u8; 0],
40+
}

Diff for: tests/headers/parm-union.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
struct Struct
2+
{
3+
void Function(union Union&);
4+
};

0 commit comments

Comments
 (0)