Fix capture of same variable twice - closes #237#245
Merged
hsutter merged 1 commit intohsutter:mainfrom Jan 29, 2023
Merged
Conversation
In current implementation when move from last use happen to variable that is captured it will be captured twice: one by copy and one moved. This change makes cppfront indentify that variable is moved and capture it once by the move and use multiple times.
Contributor
Author
|
There is only one change in regression tests - in y := "\n";
std::ranges::for_each
( view, :(x:_) = { std::cout << y$ << x << y$; } );Generates: auto y {"\n"};
std::ranges::for_each
( view, [_0 = std::move(y)](auto const& x){std::cout << _0 << x << _0;});instead of the following: auto y {"\n"};
std::ranges::for_each
( view, [_0 = y, _1 = std::move(y)](auto const& x){std::cout << _0 << x << _1;}); |
Contributor
Author
|
I have added overload of the The new overload looks: void print_to_string(std::string* str, auto& i, auto... more) {
printer.emit_to_string(str);
emit(i, more...);
printer.emit_to_string();
}; |
Owner
|
Looks good, thanks! |
Azmah-Bad
pushed a commit
to Azmah-Bad/cppfront
that referenced
this pull request
Feb 24, 2023
In current implementation when move from last use happen to variable that is captured it will be captured twice: one by copy and one moved. This change makes cppfront indentify that variable is moved and capture it once by the move and use multiple times.
Azmah-Bad
pushed a commit
to Azmah-Bad/cppfront
that referenced
this pull request
Feb 24, 2023
In current implementation when move from last use happen to variable that is captured it will be captured twice: one by copy and one moved. This change makes cppfront indentify that variable is moved and capture it once by the move and use multiple times.
zaucy
pushed a commit
to zaucy/cppfront
that referenced
this pull request
Dec 5, 2023
In current implementation when move from last use happen to variable that is captured it will be captured twice: one by copy and one moved. This change makes cppfront indentify that variable is moved and capture it once by the move and use multiple times.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In the current implementation, when the move from the last use happens to a variable captured, it will be captured twice: one by copy and one moved.
That means that the following code:
Will generate (skipping boilerplate):
This change makes cppfront identify that variable is moved, capture it once by the move, and use it multiple times. That means that the above code will generate the following: