Repository navigation
Generate an empty enum that compiles in C and Rust [patch] - #195
Merged
Merged
Conversation
ISO C has no empty enumerator list, so typedef enum Empty { } Empty;
failed with "empty enum is invalid". An enum with no members is now a
typedef of its underlying type, or of int, with a note saying why.
rustc rejects #[repr] on a zero-variant enum (E0084), so the Rust
generator leaves it off when there are no members.
Fixes #190
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X8BPy6trRZiUxiwJcbUGzR
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #190
What changed
CGenerator.GenerateEnumDeclarationalways wrotetypedef enum Name { … } Name;. ISO C does not allow an empty enumerator list, so gcc rejected the output for an enum with no members (empty enum is invalid). An enum with no members now becomes a typedef of its underlying type, or ofintif none is set. A note explains that C has no empty enum, using the sameWriteInexpressiblestyle as the generator's other notes.rustcrejects#[repr]on an enum with no variants (E0084).RustGenerator.GenerateEnumDeclarationnow omits it whenMembersis empty.The other five targets already handled an empty enum, so they are unchanged.
Tests
CGeneratorTests.Enum_WithNoMembers_IsATypedefOfItsType:Emptybecomestypedef int Empty;, andFlags : longbecomestypedef long long Flags;.CGeneratedSourceCompilesTests: the exemplar header now includes both empty enums and is compiled with-std=c11.RustGeneratorTests.Enum_WithNoVariants_HasNoRepr: checks that#[repr]is gone from an empty enum.RustGeneratedSourceCompilesTests: the exemplar now includes an empty enum withUnderlyingType = intand is compiled withrustc.With the generator changes reverted, all four tests fail. gcc reports
empty enum is invalidand rustc reports E0084. With the changes, the full suite passes (1102/1102).This is separate from #181, the empty-struct case in C. That case goes through a different code path and is not touched here.
🤖 Generated with Claude Code
https://claude.ai/code/session_01X8BPy6trRZiUxiwJcbUGzR
Generated by Claude Code