Trying to understand lvalues and rvalues

79 views
Skip to first unread message

Manik Jindal

unread,
Jan 24, 2016, 1:05:28 PM1/24/16
to ISO C++ Standard - Discussion
Hi

I was trying to understand glvalues, rvalues, lvalues, xvalues and prvalues in c++11. But I figured that I do not have a basic understanding of what lvalues and rvalues meant before c++11 (i.e. in c++03 and even before that).
Also, I tried, but I could not get my hands on a c++03 standard.

Caution: long post.

What I have understood until now (or so I believe), please correct me wherever I am wrong:
  • C/C++03 ([Ln1][Ln2])
    • "An object is a manipulable region of storage; an lvalue is an expression referring to an object..."
    • we can have non modifiable lvalues too. (const qualified lvalues are non modifiable) [an expression is modifiable, if through it we can modify the object it is referring to]
    • "Conceptually, an rvalue is just a value; it doesn't refer to an object. In practice, it's not that an rvalue can't refer to an object. It's just that an rvalue doesn't necessarily refer to an object."
    • until now: 
      • modifiable lvalue - addressable + assignable
      • non modifiable lvalue - addressable not assignable
      • rvalue - neither addressable not assignable
      • this only applies to rvalues of non-class types [Q1][Q2]
  • I understand that one can modify rvalues of class type by calling their member functions.
    • Example: http://ideone.com/GtaVpS
    • and if you return a const rvalue of class-type you would not be able to modify it. because rvalues of class-type retain their cv qualifiers.
    • Some where in the standard it must have been mentioned that non-class rvalues always are cv-unqualified, because it gets quoted a lot.
    • Hence [Q3]

Questions:
[Q1] What are class-types and non-class types?
[Q2] What's so different in rvalues of class type when compared to non-class types.
[Q3] How does one modify a non-class type rvalue? If one cannot why did the need arose in the standard to specify that non-class rvalues are always cv-unqualified.


Nicol Bolas

unread,
Jan 24, 2016, 2:54:49 PM1/24/16
to ISO C++ Standard - Discussion
On Sunday, January 24, 2016 at 1:05:28 PM UTC-5, Manik Jindal wrote:
Hi

I was trying to understand glvalues, rvalues, lvalues, xvalues and prvalues in c++11. But I figured that I do not have a basic understanding of what lvalues and rvalues meant before c++11 (i.e. in c++03 and even before that).

I just did a Google search for "glvalues, rvalues, lvalues, xvalues and prvalues". The first two links produced comprehensive information about these concepts.

Columbo

unread,
Jan 24, 2016, 3:04:06 PM1/24/16
to ISO C++ Standard - Discussion
On Sunday, January 24, 2016 at 6:05:28 PM UTC, Manik Jindal wrote:
"An object is a manipulable region of storage; an lvalue is an expression referring to an object..."

[intro.object] was amended by P0137. An object occupies a region of storage.  

Manik Jindal

unread,
Jan 24, 2016, 3:11:55 PM1/24/16
to ISO C++ Standard - Discussion
Thanks Nicol. I think I messed up when I started the post by saying that I was trying to understand glvalues, rvalues, lvalues .... TBH, I was. I have seen both the links you mentioned but was unable to understand many aspects in these. I think this is because I do not have a firm grasp on lvalues and rvalues, what they meant in C++03. And hence failed to see the points people were making and where they are coming from. I hope I have cleared up a bit about where am I coming from.

Manik Jindal

unread,
Jan 24, 2016, 3:12:36 PM1/24/16
to ISO C++ Standard - Discussion
Thanks Columbo. 

Richard Smith

unread,
Jan 29, 2016, 5:52:26 PM1/29/16
to std-dis...@isocpp.org
You may also be interested in
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0135r0.html
(approved by EWG at Kona) which touches on some of this.
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-discussio...@isocpp.org.
> To post to this group, send email to std-dis...@isocpp.org.
> Visit this group at
> https://groups.google.com/a/isocpp.org/group/std-discussion/.
Reply all
Reply to author
Forward
0 new messages