diff --git a/bindgen-tests/tests/expectations/tests/union_template_forward_decl.rs b/bindgen-tests/tests/expectations/tests/union_template_forward_decl.rs new file mode 100644 index 0000000000..c934f49a8e --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/union_template_forward_decl.rs @@ -0,0 +1,27 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +pub struct declare_union { + _unused: [u8; 0], +} +#[repr(C)] +pub union define_union { + pub value: *mut value_t, + pub dummy: ::std::os::raw::c_int, + pub _phantom_0: + ::std::marker::PhantomData<::std::cell::UnsafeCell>, +} +impl Default for define_union { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} diff --git a/bindgen-tests/tests/headers/union_template_forward_decl.hpp b/bindgen-tests/tests/headers/union_template_forward_decl.hpp new file mode 100644 index 0000000000..4fb4bc5ad9 --- /dev/null +++ b/bindgen-tests/tests/headers/union_template_forward_decl.hpp @@ -0,0 +1,17 @@ +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq +// +template +union declare_union; // Primary template declared, but never defined. + +template union declare_union { + declare_union() {} + declare_union(value_t *a_value) : value(a_value) {} + value_t *value; +}; + +template union define_union { + define_union() {} + define_union(value_t *a_value) : value(a_value) {} + value_t *value; + int dummy; +}; diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 18a4291cf9..0bff3982ae 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -1275,6 +1275,7 @@ impl CompInfo { CXCursor_ParmDecl => true, CXCursor_StructDecl | CXCursor_UnionDecl | CXCursor_ClassDecl => !cur.is_definition(), + CXCursor_ClassTemplate => kind == CompKind::Union && !cur.is_definition(), _ => false, });