fix: guard taking const State& now sees live pool state (issue #530)#681
Merged
kris-jusiak merged 1 commit intoMay 26, 2026
Merged
Conversation
…ext#530) Root cause: when both a mutable action (State&) and a const guard (const State&) name the same type, ignore::non_events produced two separate dep_list entries — State& and const State& — which caused two independent pool slots to be allocated and initialised from the same default-constructed object. Subsequent mutations via the mutable slot were therefore invisible to the const-ref slot. Fix (two parts): 1. ignore::non_events now normalises 'const U&' → 'U&' before adding the type to the dep_list, so both the mutable action and the const guard share a single pool slot. 2. A new get_arg overload for 'const T&' parameters looks up 'T&' in the pool (instead of 'const T&'), ensuring both call-sites bind to the same live object. Test: const_ref_state_dep_sees_live_state in test/ft/dependencies.cpp (compiled under BOOST_SML_CREATE_DEFAULT_CONSTRUCTIBLE_DEPS) verifies that a guard taking const State& sees the id value written by the preceding set action.
1a44783 to
9555375
Compare
Contributor
|
This has been a thorn in my side, thanks for repairing it! |
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.
Problem
When a state machine uses
BOOST_SML_CREATE_DEFAULT_CONSTRUCTIBLE_DEPSand an action mutates a state object viaState&while a subsequent guard reads it viaconst State&, the guard received a default-constructed copy instead of the live, mutated value.Root cause:
ignore::non_eventsproduced two separate dep_list entries —State&andconst State&— which caused two independent pool slots to be allocated and initialised from the same default-constructed object. Mutations via the mutable slot (State&) were invisible to the const-ref slot (const State&).Minimal repro
Fix (two parts)
1.
ignore::non_eventsnormalisation — mapconst U&→U&before inserting into the dep_list, so mutable and const references share a single pool slot:2. New
get_argoverload forconst T&— looks upT&in the pool (notconst T&) so both call-sites bind to the same live object:Test
test const_ref_state_dep_sees_live_stateadded totest/ft/dependencies.cpp(compiled underBOOST_SML_CREATE_DEFAULT_CONSTRUCTIBLE_DEPS).Closes #530