fix: re-enable const lvalue reference dependency usage#712
Conversation
attempts to solve the issue described in #711
|
Thanks for the PR @dornbirndevelops , |
|
Built this branch and it checks out — fix is correct. #711 repro compiles on GCC c++14/17/20 (macro on+off) and MSVC c++20, #530 still passes ( Only thing missing is a functional regression test — right now it's just the two header static_asserts, which never actually build an One gotcha on where to put it: #711 only reproduces with Something like #include <boost/sml.hpp>
namespace sml = boost::sml;
struct dep711 { int n{}; };
struct ev711 {};
// #711: dep used only via `const T&` must accept a const lvalue.
test const_lvalue_dependency_injection = [] {
struct c {
auto operator()() const noexcept {
using namespace sml;
auto guard = [](const dep711& d) { return d.n == 7; };
return make_transition_table(*"idle"_s + event<ev711>[guard] = X);
}
};
const dep711 d{7};
sml::sm<c> sm{d};
sm.process_event(ev711{});
expect(sm.is(sml::X));
};
test nonconst_lvalue_dependency_injection = [] {
struct c {
auto operator()() const noexcept {
using namespace sml;
auto guard = [](const dep711& d) { return d.n == 7; };
return make_transition_table(*"idle"_s + event<ev711>[guard] = X);
}
};
dep711 d{7};
sml::sm<c> sm{d};
sm.process_event(ev711{});
expect(sm.is(sml::X));
};
// #530 under normal injection: const guard sees the mutable action's write.
test const_guard_sees_live_mutation_of_injected_dep = [] {
struct c {
auto operator()() const noexcept {
using namespace sml;
auto inc = [](dep711& d) { ++d.n; };
auto check = [](const dep711& d) { return d.n == 8; };
return make_transition_table(
*"s1"_s + event<ev711> / inc = "s2"_s,
"s2"_s + event<ev711> [check] = X);
}
};
dep711 d{7};
sml::sm<c> sm{d};
sm.process_event(ev711{});
sm.process_event(ev711{});
expect(sm.is(sml::X));
expect(d.n == 8);
};plus in add_executable(test_dependencies_const_ref dependencies_const_ref.cpp)
add_test(test_dependencies_const_ref test_dependencies_const_ref)I checked this file passes on the branch and fails to compile on the pre-fix header ( |
|
Fix verified correct, the gap is a functional regression test, and it should go in a new macro-OFF file (dependencies_const_ref.cpp) since #711 doesn't reproduce with |
test covers both const and non-const dependencies
To suppress one may add : Thanks for the extra test coverage @dornbirndevelops :) |
|
LGTM :) |
|
Thank you |
Problem:
Solution:
collapse_const_refs_tthat performs normalization only if at least one non-const reference usage is presentIssue: #711
Reviewers:
@kris-jusiak
@PavelGuzenfeld