Skip to content

Commit

Permalink
fix template union forward declaration, close rust-lang#1768
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielmelody committed Feb 23, 2023
1 parent 2d99bbd commit a21ba75
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions 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 <typename value_t>
union declare_union; // Primary template declared, but never defined.

template <typename value_t> union declare_union<value_t *> {
declare_union() {}
declare_union(value_t *a_value) : value(a_value) {}
value_t *value;
};

template <typename value_t> union define_union {
define_union() {}
define_union(value_t *a_value) : value(a_value) {}
value_t *value;
int dummy;
};
3 changes: 2 additions & 1 deletion bindgen/ir/comp.rs
Expand Up @@ -1267,14 +1267,15 @@ impl CompInfo {

let kind = kind?;

debug!("CompInfo::from_ty({:?}, {:?})", kind, cursor);
println!("CompInfo::from_ty({:?}, {:?})", kind, cursor);

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(),
CXCursor_ClassTemplate => kind == CompKind::Union && !cur.is_definition(),
_ => false,
});

Expand Down

0 comments on commit a21ba75

Please sign in to comment.