Skip to content

Commit

Permalink
Identify forward declarations in params. (rust-lang#2052)
Browse files Browse the repository at this point in the history
  • Loading branch information
adetaylor authored and LoganBarnett committed Dec 2, 2023
1 parent 0be3c2b commit 61925c1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/clang.rs
Expand Up @@ -241,7 +241,7 @@ impl Cursor {
self.x.kind
}

/// Returns true is the cursor is a definition
/// Returns true if the cursor is a definition
pub fn is_definition(&self) -> bool {
unsafe { clang_isCursorDefinition(self.x) != 0 }
}
Expand Down
1 change: 1 addition & 0 deletions src/ir/comp.rs
Expand Up @@ -1249,6 +1249,7 @@ impl CompInfo {
let mut ci = CompInfo::new(kind);
ci.is_forward_declaration =
location.map_or(true, |cur| match cur.kind() {
CXCursor_ParmDecl => true,
CXCursor_StructDecl | CXCursor_UnionDecl |
CXCursor_ClassDecl => !cur.is_definition(),
_ => false,
Expand Down
40 changes: 40 additions & 0 deletions tests/expectations/tests/parm-union.rs
@@ -0,0 +1,40 @@
#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]

#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Struct {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Struct() {
assert_eq!(
::std::mem::size_of::<Struct>(),
1usize,
concat!("Size of: ", stringify!(Struct))
);
assert_eq!(
::std::mem::align_of::<Struct>(),
1usize,
concat!("Alignment of ", stringify!(Struct))
);
}
extern "C" {
#[link_name = "\u{1}_ZN6Struct8FunctionER5Union"]
pub fn Struct_Function(this: *mut Struct, arg1: *mut Union);
}
impl Struct {
#[inline]
pub unsafe fn Function(&mut self, arg1: *mut Union) {
Struct_Function(self, arg1)
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct Union {
_unused: [u8; 0],
}
4 changes: 4 additions & 0 deletions tests/headers/parm-union.hpp
@@ -0,0 +1,4 @@
struct Struct
{
void Function(union Union&);
};

0 comments on commit 61925c1

Please sign in to comment.