Skip to content

Preserve reference alternatives during rvalue visitation - #118

Open
trestoncuzzort wants to merge 1 commit into
boostorg:developfrom
trestoncuzzort:fix-rvalue-reference-visitation
Open

trestoncuzzort wants to merge 1 commit into
boostorg:developfrom
trestoncuzzort:fix-rvalue-reference-visitation

Conversation

@trestoncuzzort

@trestoncuzzort trestoncuzzort commented Oct 26, 2026 •

Copy link
Copy Markdown

Fixes #73.

Visiting a temporary variant<T&> currently passes the referenced object as an rvalue. A visitor accepting T& then fails to compile, and a visitor taking its argument by value can move from an externally owned object.

Unwrap reference alternatives through a non-moving invoke_visitor. This preserves their lvalue category, including through recursive wrappers. Owned alternatives retain their existing move behavior.

The regression covers member/free visitation, const containers and referents, mutation and identity, owned-value moves, nested recursive wrappers, binary/multi visitation, and inferred visitor results.

Validation:

  • Full test targets pass with GCC 16/C++11 and Clang 23/C++17. The new regression also passes ASan/UBSan and explicit Valgrind.
  • Pinned Linux, macOS and Windows checks verify the original compile failure and fixed regression/category matrix in both supported language modes. A direct-visitor shortcut still fails the nested-wrapper regression.

Implemented and tested with Codex assistance.

Unwrap reference content through a non-moving visitor so temporary variants retain lvalue references to externally owned objects. Preserve recursive unwrapping and owned-value moves.

Fixes boostorg#73.

Generated-by: Codex
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.

rvalue variant with lvalue references does not compile

1 participant