Add diagnostics for returning a temporary, closes #381#384
Merged
hsutter merged 1 commit intoApr 20, 2023
Merged
Conversation
Contributor
|
I think https://en.cppreference.com/w/cpp/types/reference_converts_from_temporary could be used for the general case. See https://compiler-explorer.com/z/87b6aEEc8. But that's C++23 and incompletely supported: |
b3b196b to
4fda4ff
Compare
Owner
|
Thanks! |
zaucy
pushed a commit
to zaucy/cppfront
that referenced
this pull request
Dec 5, 2023
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.


The current implementation of cppfront (65fcd0f) does not provide diagnostics for forward return temporary variables, e.g.:
forward_return_literal: () -> forward _ = { return 1; } forward_return_rvalue: () -> forward _ = { return global + 1; }Generates:
This change provides better diagnostics and handles most operators that might create a temporary variable:
/,<<,<=>,<,<=,>>,>=,>,+,-,||,|,&&,*,%,&,^,==,!=,!,&,~All other operators that return references are accepted.
All regression tests pass. Closes #381
Need to be checked
The below cases still might not be supported: