Skip to content

disallow left over bits in packed unions #21286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

Rexicon226
Copy link
Contributor

closes #19754

  • Makes packed unions require a backing int type.
  • Requires all fields in the packed union to have the same bit size.

The error message gathers the incorrect fields and prints them at the same time:

empty.zig:1:26: error: all fields must have a bit size of 6
const Bar = packed union(u6) {
                         ^~
empty.zig:7:8: note: field with bit size 9 here
    x: u9,
       ^~
empty.zig:8:8: note: field with bit size 64 here
    y: u64,
       ^~~

For backends, we can access the backing integer type through tagTypeUnordered, although maybe we should rename tag type to something else now that it has multiple meanings.

@Rexicon226
Copy link
Contributor Author

I think I approached this a bit wrong, I'm gonna re-open it later when I have more time.

@Rexicon226 Rexicon226 closed this Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: don't allow unused bits in packed unions
1 participant