fix: bind_* associating functions must respect value-category of wrapped object #1540
+36
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
The helper functions for binding associations to completion handlers, such as
bind_executor
, did not previously respect the value-category of wrapper. Consequently, when using move-only values with certain completion-handlers, build failures result since although the wrapper was an r-value, the wrapped target was not treated as such.Changes
The solution is to forward the value-category of the wrapper to the wrapped target. This is already done in other wrappers in asio, like append. For these bind wrappers, an overload of their forwarding call operator is added to each wrapper. Moving the target is in C++03 form, using
static_cast
overstd::move
, to remain consistent with the rest of asio.Failing Example
Although contrived, this example fails to build because the move-only completion handler
Intermediary
is not handled properly bybind_allocator
. I've hit this build failure in multiple more realistic scenarios, particularly when usingasio::awaitable
, where the result of the awaitable frame cannot be allocated here due to the improper value-category.