Track variant selectively so reused values round-trip - #360
Open
gennaroprota wants to merge 1 commit into
Open
Conversation
`boost::variant` and `std::variant` specialized `tracking_level` to `track_always`. With object tracking on, serializing the same variant twice by value wrote the second occurrence as a bare object reference. On load, that reference could not be resolved into a separate destination: value loads receive their destination by value, not by reference, so the tracking table has nowhere to copy from, and the second variant silently loaded as empty. So, use `track_selectively` (the default for class types) for all three variant flavors: a variant is tracked when serialized through a pointer and stored by value otherwise, matching every other value type. The tracking flag is written per object in the class info, so archives written with the old track_always variant still load correctly and no archive version bump is needed. Also add a regression test that serializes a variant twice into one archive and checks that both copies load back to the original value. Closes #203.
gennaroprota
force-pushed
the
fix/variant-value-tracking-drops-repeated-values
branch
from
July 29, 2026 13:17
f00098c to
45f9f03
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.
boost::variantandstd::variantspecializedtracking_leveltotrack_always. With object tracking on, serializing the same variant twice by value wrote the second occurrence as a bare object reference. On load, that reference could not be resolved into a separate destination: value loads receive their destination by value, not by reference, so the tracking table has nowhere to copy from, and the second variant silently loaded as empty.So, use
track_selectively(the default for class types) for all three variant flavors: a variant is tracked when serialized through a pointer and stored by value otherwise, matching every other value type. The tracking flag is written per object in the class info, so archives written with the old track_always variant still load correctly and no archive version bump is needed.Also add a regression test that serializes a variant twice into one archive and checks that both copies load back to the original value.
Closes #203.