Skip to content

Commit 0a09719

Browse files
committed
fix template union forward declaration, close #1768
1 parent 2d99bbd commit 0a09719

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

bindgen-tests/tests/expectations/tests/union_template_forward_decl.rs

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq
2+
//
3+
template <typename value_t>
4+
union declare_union; // Primary template declared, but never defined.
5+
6+
template <typename value_t> union declare_union<value_t *> {
7+
declare_union() {}
8+
declare_union(value_t *a_value) : value(a_value) {}
9+
value_t *value;
10+
};
11+
12+
template <typename value_t> union define_union {
13+
define_union() {}
14+
define_union(value_t *a_value) : value(a_value) {}
15+
value_t *value;
16+
int dummy;
17+
};

bindgen/ir/comp.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1267,14 +1267,17 @@ impl CompInfo {
12671267

12681268
let kind = kind?;
12691269

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

12721272
let mut ci = CompInfo::new(kind);
12731273
ci.is_forward_declaration =
12741274
location.map_or(true, |cur| match cur.kind() {
12751275
CXCursor_ParmDecl => true,
12761276
CXCursor_StructDecl | CXCursor_UnionDecl |
12771277
CXCursor_ClassDecl => !cur.is_definition(),
1278+
CXCursor_ClassTemplate => {
1279+
kind == CompKind::Union && !cur.is_definition()
1280+
}
12781281
_ => false,
12791282
});
12801283

0 commit comments

Comments
 (0)