C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: what is the "glvalue result" in [stmt.return] section
From: jim x (xmh970252187_at_[hidden])
Date: 2020-09-01 22:42:26


Hi Mckesson, thank you for participating this discussion. I can understand
that the value category of this postfix expression "func(a)" is
`glvalue(xvalue)`, because its return type is a rvalue reference to object.
But, I can't understand this sentence you said `the "glvalue result" of
"func(a)" is whatever object `a` represents`. If I don't misunderstand, the
intent of the rule is that let the `rf` bind to the operand of return
statement ,namely `a`(by copy-initialization). why do you said `a` is the
so-called "glvalue result", even if I agree with that `a` is a glvalue.

Jason McKesson via Std-Discussion <std-discussion_at_[hidden]>
于2020年9月2日周三 上午11:20写道:

> 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
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>



STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups