3

https://stackoverflow.com/a/3601661/368896 and others provide a definition of lvalue and rvalue (referencing the standard), as well as xvalue, glvalue, and prvalue.

However, the definition of rvalue refers to the definition of xvalue, and the definition of xvalue refers to "the result of certain kinds of expressions involving rvalue references".

Therefore, to understand the technical definition of rvalue, one must determine which kinds of "expressions involving rvalue references" are referred to in the above definition. I have taken the time to attempt to follow the standard (and different postings) to track through this definition. I would like a definition that does not require tracking through other definitions (except for more obvious, lower-level definitions).

Is this a wild goose chase? Is it possible to provide a concise, but rigorous, definition of the difference between an rvalue expression and an lvalue expression, that covers all possible cases, and that does not make reference to "the result of certain kinds of expressions involving rvalue references"? If so, what is such a definition?

Community
  • 1
  • 1
Dan Nissenbaum
  • 12,293
  • 18
  • 99
  • 168
  • 1
    You're mixing apples and oranges here. An `rvalue` is a group that encompasses the `prvalues` and `xvalues` categories, while an `lvalue` is a category itself. You may want to clarify. – Xeo Mar 10 '13 at 16:32
  • 1
    Also, [this question](http://stackoverflow.com/q/11581903/500104) should be helpful. – Xeo Mar 10 '13 at 16:34
  • @Xeo - However, `rvalue` (including both `prvalue` and `xvalue`) does not overlap `lvalue` - I was careful about that. Therefore, there is an unambiguous distinction. – Dan Nissenbaum Mar 10 '13 at 16:40
  • 1
    An rvalue reference is a type, it's not tautological to define rvalues in terms of them. – Jonathan Wakely Mar 10 '13 at 17:13
  • 1
    in a nutshell, an rvalue is an expression that refers to something that expires soon or for which the issue of when it expires makes no sense. – Johannes Schaub - litb Mar 10 '13 at 17:38
  • @JonathanWakely Indeed, it is not tautological; nor did I suggest so. – Dan Nissenbaum Mar 10 '13 at 18:33
  • @JohannesSchaub-litb I do know what an `rvalue` is at the "working" level you describe; I would like to know if a concise, rigorous technical definition if possible along the lines of my question. – Dan Nissenbaum Mar 10 '13 at 18:36
  • 3
    If a concise, rigourous definition existed the standard would use it. – Jonathan Wakely Mar 10 '13 at 18:43
  • 1
    +1 well i see @AndyProwl deleted his posted answer, and I discarded mine even before posting it. conclusion: this is spaghetti territory of the standard. :-) – Cheers and hth. - Alf Mar 10 '13 at 20:26
  • How do you define "concise"? The category of xvalues includes many special cases. – Nicol Bolas Mar 10 '13 at 21:59
  • @Cheersandhth.-Alf: I wasn't sure if my answer was appropriate, after posting I had the feeling it was just too subjective. Then after 40 views and zero upvotes, I thought I probably wasn't the only one thinking it, so I just deleted it ;) – Andy Prowl Mar 10 '13 at 22:00
  • 1
    @JonathanWakely The standard is filled with historically-motivated language and structure, so the logic is sometimes circuitous. There may be good reasons for this, but in my opinion it is far from concise. – Dan Nissenbaum Mar 11 '13 at 01:57
  • I'm not sure what you mean by historically-motivated, there's no "Annotated Reference Manual Preservation Society" at work :-) The whole concept of _prvalues_, _glvalues_ and _xvalues_ is very new, not historical, so if the wording could easily have been made more concise when it was edited then it would have been. For another example, the notion of sequence points was removed and replaced with new wording for C++11. If you can express the same rules in a more concise way please submit a proposal, otherwise I tend to assume it's not concise because it's really quite complicated. – Jonathan Wakely Mar 11 '13 at 09:06
  • The terms "lvalue" and "rvalue" have historical origins, but the concepts themselves are motivated by what's useful and meaningful _now_ not by their historical meanings. The meaning of the terms is not determined by the historical origin. – Jonathan Wakely Mar 11 '13 at 09:15
  • @JonathanWakely I don't mean that the text is **intentionally** historically motivated. The current standard uses the previous standard as a starting point, and this historical relationship shines through in terms of concision. That doesn't mean that it's not possible to take a stab at a more concise definition of the difference between an `rvalue` expression and an `lvalue` expression - though it might involve a list of special cases. – Dan Nissenbaum Mar 11 '13 at 13:01
  • 1
    You might be interested in http://open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3550.pdf – Jonathan Wakely Mar 19 '13 at 17:15

1 Answers1

2

What constitutes an rvalue is defined by a set of ad-hoc rules, so I don't think "concise" is going to be possible.

xvalues are fairly easy: they're "stuff that returns a T&&." This includes functions returning that, explicit casts to T&&, accessing a class data member via a T&& (whether directly or via pointer-to-data-member).

The problem is prvalues, which are all over the place. You can get a general sense of what they are, but the specifics involves a lot of ad-hoc rules. Like the fact that return valueArgument; can consider valueArgument to be a prvalue, even though it's an lvalue everywhere else.

Basically, the standards committee went through the standard and looked for places where they wanted to implicitly move, and then said, "You're a prvalue."

So a "concise but rigorous" definition is not going to be likely.

Nicol Bolas
  • 378,677
  • 53
  • 635
  • 829