fix dangling reference in pool_type_impl<T&> init constructor (#504)#674
Merged
kris-jusiak merged 1 commit intoMay 23, 2026
Conversation
Collaborator
|
LGTM, thanks, there is merge conflict though, coule you rebase |
…oost-ext#504) The pool_type_impl<T&> specialisation (active under BOOST_SML_CREATE_DEFAULT_CONSTRUCTIBLE_DEPS) had a copy-paste bug in the constructor that accepts an (init, object) pair: constexpr pool_type_impl(const init &i, const TObject &object) : value(i, object) {} 'value' is a T& reference member. In a member-initialiser list the expression 'value(i, object)' for a reference type does NOT call a two-argument constructor; it applies the C++ comma operator — evaluates i (discarding the result), evaluates object, and binds 'value' to the result. 'object' is a function parameter (const TObject&) which goes out of scope once the constructor returns, leaving 'value' as a dangling reference. Fix: initialise the backing-store member value_ by extracting the T from the source pool via try_get, then bind the reference member value to value_: constexpr pool_type_impl(const init &, const TObject &object) : value_{try_get<T>(&object)}, value{value_} {} This stores a local copy in value_ and keeps the reference valid for the lifetime of the pool_type_impl object. Regression test added in test/ft/dependencies.cpp: ref_dep_copy_from_pool_not_dangling — SM with reference dep + sub-SM exercises the pool(const pool<TArgs...>&) path that instantiates the fixed constructor. Fixes boost-ext#504.
5c36ddb to
2f24cc4
Compare
Contributor
Author
On it. |
Contributor
Author
I'm also making sure the CI runs green. If its possible please wait till all is GO next time. |
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
The
pool_type_impl<T&>specialisation (active underBOOST_SML_CREATE_DEFAULT_CONSTRUCTIBLE_DEPS) contains a copy-paste bug in its(init, object)constructor:valueis aT&(reference) member. In a member-initialiser list,value(i, object)for a reference type does not call a two-argument constructor — it applies the C++ comma operator: evaluatesi(discards result), then evaluatesobject, and bindsvalueto the result.objectis a function parameter (const TObject&) that goes out of scope once the constructor returns, leavingvalueas a dangling reference. Any subsequent access throughvalueis undefined behaviour.Fix
Initialise the backing-store member
value_by extractingTfrom the source pool viatry_get, then bind the reference membervaluetovalue_:This stores a local copy in
value_and keeps the reference valid for the lifetime of thepool_type_implobject — matching the pattern already used in the other constructors of this specialisation.Test
Regression test
ref_dep_copy_from_pool_not_danglingadded intest/ft/dependencies.cpp: an SM with a reference dep (dep504&) and a sub-state machine exercises thepool(const pool<TArgs...>&)constructor path that instantiates the fixed constructor.Fixes #504.