Skip to content

Commit 92a2192

Browse files
authored
Fix Bugzilla 14945 - unions are missing from the ABI page (#3915)
1 parent 4b21a89 commit 92a2192

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

spec/abi.dd

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,14 @@ $(H2 $(LNAME2 delegates, Delegates))
6868
function's stack frame (nested functions).
6969
)
7070

71-
$(H2 $(LNAME2 structs, Structs))
71+
$(H2 $(LNAME2 structs, Structs and Unions))
7272

73-
$(P Conforms to the target's C ABI struct layout.)
73+
$(P These conform to the target's C ABI struct layout, except:)
74+
75+
* An `extern(D)` struct or union with no fields has size 1, not 0.
76+
See $(DDSUBLINK spec/struct, struct_layout, Struct Layout).
77+
* Unions are $(RELATIVE_LINK2 name_mangling, name-mangled) as if they were structs.
78+
* The rest of this document treats unions extrinsically the same as structs.
7479

7580
$(H2 $(LNAME2 classes, Classes))
7681

spec/struct.dd

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,18 @@ $(H2 $(LNAME2 struct_layout, Struct Layout))
176176
the first field and the start of the object.
177177
)
178178

179-
$(P Structs with no fields of non-zero size (aka $(I Empty Structs)) have a size of one byte.)
179+
$(P $(DDSUBLINK spec/attribute, linkage, `extern(D)`) structs with no fields of non-zero
180+
size (aka $(I Empty Structs)) have a size of one byte.)
181+
182+
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
183+
---
184+
extern(C) struct C {}
185+
struct D {}
186+
187+
static assert(C.sizeof == 0);
188+
static assert(D.sizeof == 1);
189+
---
190+
)
180191

181192
$(P Non-static $(RELATIVE_LINK2 nested, function-nested D structs), which access the context of
182193
their enclosing scope, have an extra field.

0 commit comments

Comments
 (0)