Skip to content

Return reference form std::strong_ordering rules - #660

Merged
nunoplopes merged 6 commits into
Cpp2Rust:masterfrom
lucic71:6-strong-ordering-references
Nov 21, 2026
Merged

nunoplopes merged 6 commits into
Cpp2Rust:masterfrom
lucic71:6-strong-ordering-references

Conversation

@lucic71

@lucic71 lucic71 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@lucic71
lucic71 force-pushed the 6-strong-ordering-references branch from 7a60cc1 to f3b3a35 Compare November 19, 2026 09:53
@nunoplopes

Copy link
Copy Markdown
Contributor

why this change?

@lucic71

lucic71 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Matches the way the header declares it and makes this code work: const std::strong_ordering &l = std::strong_ordering::less;

It's the same strategy we use for std::cout and the other global variables in STL: return them by reference

@lucic71
lucic71 force-pushed the 6-strong-ordering-references branch from f3b3a35 to a8a8360 Compare November 19, 2026 10:00
@nunoplopes

Copy link
Copy Markdown
Contributor

Uhm, I don't like this. A const & can bind to a temporary, which is what C++ does in this case.
This will show up in other cases, for example:

struct S { int x; int y; };
S foo();

int f() {
    const int &i = foo().x;
    return i;
}

@nunoplopes
nunoplopes merged commit c46adda into Cpp2Rust:master Nov 21, 2026
4 of 9 checks passed
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