C++ Logo

std-discussion

Advanced search

Re: what is the "glvalue result" in [stmt.return] section

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Tue, 1 Sep 2020 23:20:33 -0400
On Tue, Sep 1, 2020 at 11:02 PM jim x via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> Hi, everyone.
> please forgive me to bother you. I have a question, that is what does "glvalue result " mean ? Is it a defined terminology wording in the standard? Please consider the above code.
>
> > int&& func(int& a){
> > return std::move(a);
> > }
> > int main(){
> > int a = 0;
> > int&& rf = func(a);
> >}
>
> The rule in [stmt.return] <https://timsong-cpp.github.io/cppwp/n4659/stmt.return#2> says that "the return statement initializes the glvalue result or prvalue result object of the (explicit or implicit) function call by copy-initialization from the operand. "
>
> So, please consider this statement "int&& rf = func(a);", what is the "glvalue result" in this declaration?

`func` is a function that returns an `int&&`. Invoking a function that
returns an `int&&` is an expression whose value category is "glvalue".
The `return` statement inside of a function initializes the "result"
of a call to that function.

So the "glvalue result" of "func(a)" is whatever object `a`
represents, thanks to your `return` statement.

The declaration has no "glvalue result"; only the expression `func(a)` does.

> I'm not sure whether the "glvalue result" refers to what the following rule says:
> >The result of a glvalue is the entity denoted by the expression.
>
> if It means that, I have to say that in the declaration "int&& rf = func(a);" where "rf" is a declarator-id rather than an expression, how could `rf` be called an expression? much less to call it a glvalue. If the above rule is not actually the definition for "glvalue result", then what does it refer to?
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion

Received on 2020-09-01 22:24:11