Store enums wider than int at full width instead of truncating#354
Open
gennaroprota wants to merge 1 commit into
Open
Store enums wider than int at full width instead of truncating#354gennaroprota wants to merge 1 commit into
gennaroprota wants to merge 1 commit into
Conversation
gennaroprota
force-pushed
the
fix/enum-serialization-preserves-wide-values
branch
from
July 22, 2026 06:46
68d9b1e to
58e3c6e
Compare
Enumerator serialization cast every value to `int` on save and back on load. For an `enum` whose underlying type does not fit in an `int`, for example a scoped enum on long long with a value above `INT_MAX`, that cast silently truncated the value, and users could not intervene because the archive routes every enum through this path before any user serialization is consulted. An enum is now saved through an integer sized to its underlying type: int when the underlying type is no wider than int, otherwise the underlying type itself. The common case (including scoped enums that do not name a type, and narrow underlying types such as char, which stay on the int path to avoid the archives' character handling) is byte for byte identical to before, so existing archives and data are unaffected. Only enums that genuinely need the extra width change on the wire, and those were being corrupted anyway. The archive library version is bumped to 21. Fixes #353.
gennaroprota
force-pushed
the
fix/enum-serialization-preserves-wide-values
branch
from
July 23, 2026 06:06
58e3c6e to
ac1489c
Compare
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.
Enumerator serialization cast every value to
inton save and back on load. For anenumwhose underlying type does not fit in anint, for example a scoped enum on long long with a value aboveINT_MAX, that cast silently truncated the value, and users could not intervene because the archive routes every enum through this path before any user serialization is consulted.An enum is now saved through an integer sized to its underlying type: int when the underlying type is no wider than int, otherwise the underlying type itself. The common case (including scoped enums that do not name a type, and narrow underlying types such as char, which stay on the int path to avoid the archives' character handling) is byte for byte identical to before, so existing archives and data are unaffected. Only enums that genuinely need the extra width change on the wire, and those were being corrupted anyway.
The archive library version is bumped to 21.
Fixes issue #353.