Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[class.temporary] p6.11 Returned reference is clearer than returned value #6001

Closed
xmh0511 opened this issue Nov 24, 2022 · 3 comments
Closed

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Nov 24, 2022

[class.temporary] p6.11 says:

The lifetime of a temporary bound to the returned value in a function return statement ([stmt.return]) is not extended; the temporary is destroyed at the end of the full-expression in the return statement.

In [stmt.return], we say

the return statement initializes the returned reference or prvalue result object of the (explicit or implicit) function call by copy-initialization from the operand.

In [class.temporary] p6.11, it should mean returned reference.

@tkoeppe
Copy link
Contributor

tkoeppe commented Nov 28, 2022

A function can't really return a refernence. The return type of a function can be a reference type, but that just means that the function returns a glvalue. So maybe it'd be better to change [stmt.return].

@xmh0511
Copy link
Contributor Author

xmh0511 commented Nov 29, 2022

I suggested in #5415, to say, the return statement should model a declaration T v = E where T is the return type of the function and E is the expr-or-braced-init-list of the return statement, and then say v is lvalue if T is lvalue reference type, xvalue if T is rvalue reference type, and prvlaue otherwise, such an invented declaration is a part of the full-expression established by the return statement, in this logic, the lifetime of temporary object created in the declaration is consistent with that of [class.temporary] p6.11. We can say the result of the function call is the v established by the return statement that transferred the flow control.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Nov 30, 2022

Maybe fixed by cplusplus/CWG#186

@xmh0511 xmh0511 closed this as completed Nov 30, 2022
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

No branches or pull requests

2 participants