-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
acceptedThis proposal is planned.This proposal is planned.enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
Description
Related:
- Proposal: Rename
packedkeyword tobitpack#12852 - make backing type of
packed structandpacked unionmandatory #24715 - Proposal: make
packedundefinedsemantics consistent with those of integers #25279 - do not allow
enum/packed struct/packed unioninexternpositions if backing type is implicit #24714
const std = @import("std");
const expect = std.testing.expect;
const U = packed union(u16) {
a: u16,
b: packed struct(u16) {
a: u7,
b: u9,
},
};
test "packed union with explicit integer type" {
const x: u16 = 1234;
const u: U = @bitCast(x);
try expect(u.a == 1234);
try expect(u.b.a == 82);
try expect(u.b.b == 9);
}Currently gives:
test.zig:4:24: error: packed union does not support enum tag type
const U = packed union(u16) {
^~~
Instead, this test should pass.
Semantics Clarifications
When combined with #24714:
- just like enums, the type has well-defined memory layout if and only if explicit backing integer provided
- just like enums, the type is allowed in extern contexts if and only if explicit backing integer provided
- just like enums, the type is allowed in switch expressions independent of explicit backing integer existing
- just like enums, the type supports equality independent of explicit backing integer existing
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
acceptedThis proposal is planned.This proposal is planned.enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.