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

[over.match.copy]: "return lvalues or xvalues" makes me uncomfortable #2053

Closed
languagelawyer opened this issue Apr 27, 2018 · 4 comments
Closed
Assignees

Comments

@languagelawyer
Copy link
Contributor

languagelawyer commented Apr 27, 2018

UPD: [over.match.copy] and [over.match.conv]

The sections [over.match.copy] and [over.match.conv] have statements like: "Conversion functions that return “reference to X” return lvalues or xvalues ..."

[diff.expr]/4 is also broken: "C++ is an object-oriented language, placing relatively more emphasis on lvalues. For example, functions may return lvalues."

"return value category" sounds illiterate for me.

Proposed wording:

The result of calling a
conversion function that returns ``reference to
\tcode{X}''
is
lvalue or xvalue, depending on the type of reference, of type
\tcode{X}
and is therefore considered to yield
\tcode{X}
for this
process of selecting candidate functions.
@zygoloid
Copy link
Member

"Result" is defined as the value/object returned by the function call, so I don't think that's quite right. We want to say that the call expression is an lvalue or xvalue. Maybe:

A call to a conversion function returning "reference to X" is a glvalue of type X, and such a conversion function is therefore considered to yield X for this process of selecting candidate functions.

?

@jensmaurer
Copy link
Member

jensmaurer commented Apr 27, 2018

Strictly speaking, we don't need "therefore" in normative text. We're not arguing, we're defining rules. Just saying "A conversion function returning "reference to X" is considered to yield X for this process of selecting candidate functions." is good enough. But, we're sometimes a bit tutorial-esque in the standard, so why not here, too?

@languagelawyer
Copy link
Contributor Author

languagelawyer commented Apr 27, 2018

"Result" is defined as the value/object returned by the function call, so I don't think that's quite right.

Then the note [basic.lval]/4 needs fix? It says "An expression is an xvalue if it is: the result of calling a function, whether implicitly or explicitly, whose return type is an rvalue reference to object type"

There already exists PR about [basic.lval]/4 — #2045 — so could the fix for "xvalue is ... the result of calling a function" be added into it?

@tkoeppe
Copy link
Contributor

tkoeppe commented Apr 28, 2018

I'm inclined to call this NAD. I have no problem with "returning an xvalue"; in fact, that's how I usually say it myself when the distinctions matter.

To me, this fits as follows: as a general statement that I think sounds meaningful to most programmers, regardless of language, "a function returns a value" is a useful shorthand for "the result of evaluating a function call expression is a value". Now all we're doing is extending this schema to be specific about the category of that value.

Jens's change is fine (though I think we'd be OK without it, too), but I wouldn't want to consider "f returns an int lvalue" to be inappropriate language. I find it very useful and concise language.

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

4 participants