Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/boost/sml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,9 @@ template <class T>
struct pool_type_impl<T &, aux::enable_if_t<aux::is_constructible<T>::value && aux::is_constructible<T, const T &>::value>>
: pool_type_base {
constexpr explicit pool_type_impl(T &val) : value{val} {} // bind ref directly
constexpr explicit pool_type_impl(missing_ctor_parameter<T>) : value_{}, value{value_} {} // default-construct backing store
template <class TObject>
constexpr explicit pool_type_impl(TObject val) : value_{val}, value{value_} {}// default-construct backing store
constexpr explicit pool_type_impl(TObject val) : value_{val}, value{value_} {}
// #504: cross-pool copy — extract T into the local backing store first, then
// bind value to it. The naive ': value(i, object)' was a comma-expression
// that bound value directly to the pool parameter (dangling after return).
Expand Down
5 changes: 5 additions & 0 deletions test/ft/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/issue_552_sub_sm_dep_identity.cpp)
add_test(test_issue_552_sub_sm_dep_identity test_issue_552_sub_sm_dep_identity)
endif()

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/issue_718_expected_member.cpp)
add_executable(test_issue_718_expected_member issue_718_expected_member.cpp)
add_test(test_issue_718_expected_member test_issue_718_expected_member)
endif()

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/issue_317_bare_internal_transition.cpp)
add_executable(test_issue_317_bare_internal_transition issue_317_bare_internal_transition.cpp)
add_test(test_issue_317_bare_internal_transition test_issue_317_bare_internal_transition)
Expand Down
98 changes: 98 additions & 0 deletions test/ft/issue_718_expected_member.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#define BOOST_SML_CREATE_DEFAULT_CONSTRUCTIBLE_DEPS
// cppcheck-suppress missingIncludeSystem
#include <boost/sml.hpp>
// cppcheck-suppress missingIncludeSystem
#include <cstddef>
// cppcheck-suppress missingIncludeSystem
#include <vector>
#if defined(__has_include)
#if __has_include(<version>)
// cppcheck-suppress missingIncludeSystem
#include <version>
#endif
#endif
#if defined(__cpp_lib_expected)
// cppcheck-suppress missingIncludeSystem
#include <expected>
#endif

namespace sml = boost::sml;

struct e718 {};

struct greedy718 {
int value{};
greedy718() = default;
template <class U>
// cppcheck-suppress noExplicitConstructor
greedy718(U&&) : value{-1} {}
};

struct greedy_first_member718 {
greedy718 member;
};

test default_dep_with_greedy_first_member_is_value_initialized_and_shared = [] {
static int value_on_entry = -2;
static int value_on_event = -2;

struct c {
auto operator()() const noexcept {
using namespace sml;
return make_transition_table(
*state<greedy_first_member718> + event<e718> / [](greedy_first_member718& s) { value_on_event = s.member.value; } = X,
state<greedy_first_member718> + on_entry<_> /
[](greedy_first_member718& s) {
value_on_entry = s.member.value;
s.member.value = 7;
});
}
};

sml::sm<c> sm;
expect(value_on_entry == 0);
sm.process_event(e718{});
expect(value_on_event == 7);
expect(sm.is(sml::X));
};

test default_dep_with_initializer_list_ctor_is_empty = [] {
static std::size_t size_on_event = 1;

struct c {
auto operator()() const noexcept {
using namespace sml;
return make_transition_table(*state<class idle718> + event<e718> / [](std::vector<int>& v) { size_on_event = v.size(); } =
X);
}
};

sml::sm<c> sm;
sm.process_event(e718{});
expect(size_on_event == 0u);
expect(sm.is(sml::X));
};

#if defined(__cpp_lib_expected)
struct expected_first_member718 {
std::expected<int, int> member;
};

test default_dep_with_std_expected_first_member_is_shared = [] {
static int value_on_event = 0;

struct c {
auto operator()() const noexcept {
using namespace sml;
return make_transition_table(
*state<expected_first_member718> + event<e718> / [](expected_first_member718& s) { value_on_event = *s.member; } = X,
state<expected_first_member718> + on_entry<_> / [](expected_first_member718& s) { s.member = 1; });
}
};

sml::sm<c> sm;
sm.process_event(e718{});
expect(value_on_event == 1);
expect(sm.is(sml::X));
};
#endif
Loading