Skip to content

Commit 5d7f684

Browse files
committed
codegen: Avoid crashing on variadic unions without layout information.
1 parent 2613129 commit 5d7f684

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

bindgen-tests/tests/expectations/tests/variadic-union.rs

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
template <typename... _Types> union _Variadic_union {
2+
_Variadic_union() = default;
3+
};

bindgen/codegen/mod.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,18 +2337,17 @@ impl CodeGenerator for CompInfo {
23372337
}
23382338
}
23392339
} else if is_union && !forward_decl {
2340-
// TODO(emilio): It'd be nice to unify this with the struct path
2341-
// above somehow.
2342-
let layout = layout.expect("Unable to get layout information?");
2343-
if struct_layout.requires_explicit_align(layout) {
2344-
explicit_align = Some(layout.align);
2345-
}
2346-
2347-
if !struct_layout.is_rust_union() {
2348-
let ty = helpers::blob(ctx, layout, false);
2349-
fields.push(quote! {
2350-
pub bindgen_union_field: #ty ,
2351-
});
2340+
if let Some(layout) = layout {
2341+
// TODO(emilio): It'd be nice to unify this with the struct path above somehow.
2342+
if struct_layout.requires_explicit_align(layout) {
2343+
explicit_align = Some(layout.align);
2344+
}
2345+
if !struct_layout.is_rust_union() {
2346+
let ty = helpers::blob(ctx, layout, false);
2347+
fields.push(quote! {
2348+
pub bindgen_union_field: #ty ,
2349+
});
2350+
}
23522351
}
23532352
}
23542353

0 commit comments

Comments
 (0)