Skip to content

callback: forward rvalue args - #950

Closed
benedekkupper wants to merge 1 commit into
intel:mainfrom
benedekkupper:fix-callback-forwarding
Closed

callback: forward rvalue args#950
benedekkupper wants to merge 1 commit into
intel:mainfrom
benedekkupper:fix-callback-forwarding

Conversation

@benedekkupper

Copy link
Copy Markdown

Preserve value category in callback::builder::run so services taking T&& receive rvalues instead of lvalues.
Add a regression test for callback::service<MoveOnlyPayload&&>.

Preserve value category in callback::builder::run so services
taking T&& receive rvalues instead of lvalues.
Add a regression test for callback::service<MoveOnlyPayload&&>.

Signed-off-by: Benedek Kupper <kupper.benedek@gmail.com>
@elbeno

elbeno commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

The reason it didn't do this before is that it's inside a fold expression. If there are multiple calllbacks you end up with a use-after-move.

@benedekkupper

Copy link
Copy Markdown
Author

The reason it didn't do this before is that it's inside a fold expression. If there are multiple calllbacks you end up with a use-after-move.

This is a valid concern and one that I pondered too, but without a better alternative in mind I went with it anyway (just adding a comment at the callback type definition). For correctness though it should either allow rvalue forwarding, or explicitly forbid it by a requires clause.

@elbeno

elbeno commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution! Based on the discussion here I fixed this problem in a slightly more robust way in #953.

@elbeno elbeno closed this Aug 3, 2026
@benedekkupper

Copy link
Copy Markdown
Author

I love the solution, thanks!

@benedekkupper
benedekkupper deleted the fix-callback-forwarding branch August 3, 2026 06:51
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.

2 participants