Fix call unwrapping optimization #5919
Merged
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.
Fix regression in #5808.
We can't move out lvalue reference.
The optimization for lvalue references is still possible, but we have to handle this case slightly differently.
Now, if the function is passed as lvalue, we copy from the passed function. instead of moving it out.
Other cases of lvalue reference in call unwrapping:
move_only_function:[func.wrap.move.ctor]/6and the definition ofmove_only_functionenforces that attempt to use lvalue reference here won't compile. So no handling is needed.copyable_function: will need to handle lvalue reference with this approach applied in one more place, in addition to these three placesfunction_ref. There can be lvalue references. But I don't know if we want to nullify moved-outfunction_refor not. More natural would be to leave moved outfunction_refintact, so we will always do as if we have lvalue reference.