Skip to content

Commit 1b5b444

Browse files
author
Dan Robertson
committed
Allow zero sized unions to be defined
A union may be defined in C that contains only zero sized types. We should in turn generate a rust union in this case.
1 parent b7b501f commit 1b5b444

File tree

3 files changed

+162
-1
lines changed

3 files changed

+162
-1
lines changed

bindgen-tests/tests/expectations/tests/struct_with_anon_union_of_array_members.rs

Lines changed: 148 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// bindgen-flags: --default-non-copy-union-style manually_drop
2+
struct bpf_array {
3+
union {
4+
struct {
5+
struct {} __empty_value1;
6+
char value1[];
7+
};
8+
struct {
9+
struct {} __empty_value2;
10+
char value2[];
11+
};
12+
};
13+
};

bindgen/ir/comp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ impl CompInfo {
17501750
return (false, false);
17511751
}
17521752

1753-
if layout.is_some_and(|l| l.size == 0) {
1753+
if layout.is_some_and(|l| l.size == 0) && union_style != NonCopyUnionStyle::ManuallyDrop {
17541754
return (false, false);
17551755
}
17561756

0 commit comments

Comments
 (0)