Skip to content

docs: document on_entry<_> multi-TU limitation and dispatch priority (#565)#703

Merged
kris-jusiak merged 5 commits into
boost-ext:masterfrom
PavelGuzenfeld:docs/issue-565-on-entry-multi-tu
May 29, 2026
Merged

docs: document on_entry<_> multi-TU limitation and dispatch priority (#565)#703
kris-jusiak merged 5 commits into
boost-ext:masterfrom
PavelGuzenfeld:docs/issue-565-on-entry-multi-tu

Conversation

@PavelGuzenfeld
Copy link
Copy Markdown
Contributor

Summary

Closes #565 (documentation fix — no library behaviour change).

What was happening

on_entry<_> maps to a generic on_entry<_, _> handler that is instantiated for every event that can reach the state, including the internal back::initial and back::anonymous events. When the action has a generic (auto/template) call operator, each event type generates a distinct template specialisation. Placing only a declaration in a header and defining the body in a separate .cpp leaves the initial-event specialisation with no definition → linker error even though the code looks correct.

Changes

include/boost/sml.hpp — comment block added above the on_entry struct:

  • Explains the instantiation-per-event behaviour
  • Explains why multi-TU generic actions fail (linker "undefined reference" for initial specialisation)
  • Lists three workarounds: define inline, use on_entry<E> with a specific type, or use a non-generic call operator

test/ft/states.cpp — new test on_entry_wildcard_fires_for_all_events:

  • Adds s3 state at file scope (needed by the test)
  • Verifies dispatch priority: when both on_entry<_> and on_entry<e1> are registered for the same state, the specific handler fires for e1 and the wildcard is the fallback for events without a specific handler (here e2)

Verified

  • GCC C++14 / C++17 / C++20: all tests pass
  • MSVC C++20: compiles cleanly (cl.exe /W4 /WX)

…(issue boost-ext#565)

on_entry<_> instantiates its action for every event that can reach the
state — including back::initial and back::anonymous — because it maps to
a generic on_entry<_, _> handler. When the action has a generic (auto/template)
call operator, each event type generates a distinct template specialisation.
Placing only a declaration in a header and defining the body in a separate .cpp
leaves the `initial`-event specialisation undefined → linker error.

Add a comment above the on_entry struct in sml.hpp explaining this, the two
workarounds (define inline; or use on_entry<E> with a specific event type), and
the dispatch priority rule (specific handler wins; wildcard is fallback for
events without a specific handler).

Add test `on_entry_wildcard_fires_for_all_events` to test/ft/states.cpp verifying:
- on_entry<e1> fires when entering via e1 (specific handler takes priority;
  wildcard does NOT fire)
- on_entry<_> fires when entering via e2 (no specific handler → wildcard fires)
@kris-jusiak kris-jusiak merged commit 0fe36fd into boost-ext:master May 29, 2026
5 checks passed
@PavelGuzenfeld PavelGuzenfeld deleted the docs/issue-565-on-entry-multi-tu branch May 29, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong Action is instantiated and called for initial event

2 participants