5

It took me quite some time to understand the difference between an rvalue and a temporary object. But now the final committee draft states on page 75:

An rvalue [...] is an xvalue, a temporary object or subobject thereof, or a value that is not associated with an object.

I can't believe my eyes. This must be an error, right?


To clarify, here is how I understand the terms:

#include <string>

void foo(std::string&& str)
{
    std::cout << str << std::endl;
}

int main()
{
    foo(std::string("hello"));
}

In this program, there are two expressions that denote the same temporary object: the prvalue std::string("hello") and the lvalue str. Expressions are not objects, but their evaluation might yield one. Specifically, the evaluation of a prvalue yields a temporary object, but a prvalue IS NOT a temporary object. Does anyone agree with me or have I gone insane? :)

Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
  • 2
    You might consider asking the standards people directly by posting a question to comp.lang.c++.std – Edward Strange Jun 09 '10 at 17:07
  • @Noah: I did. Let's see what happens :) – fredoverflow Jun 09 '10 at 17:36
  • [link to comp.std.c++ thread](http://groups.google.de/group/comp.std.c++/browse_thread/thread/5cdae718218a462c) – fredoverflow Jun 10 '10 at 21:48
  • I have forgotten where I saw it, but someone from the C++ committee had posted a photo of a whiteboard showing "the new expression type hierarchy;" the next day he posted another similar but different photo with the caption "well, that didn't last long" (now I'm irritated because I can't remember who it was!) Clearly this is a somewhat contentious issue. – James McNellis Jul 15 '10 at 15:30
  • 1
    "_Does anyone agree with me or have I gone insane? :)_" Someone went insane, and that someone is not you. ;) – curiousguy Dec 25 '11 at 22:05
  • An expression does not denote a temporary object. It denotes a series of operations, which yield an object. That object is the result of evaluating the expression, but separate from the expression. – Ben Voigt Oct 20 '12 at 02:58

2 Answers2

2

Yes, i agree with you. This should be fixed in my opinion, and several people i deeply pay respect to have risen the exact same question about this.

Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
0

This isn't as complicated as it sounds. I am referring to the now finalized standard ISO/IEC 14882-2011. Page 78 says:

An xvalue (an “eXpiring” value) also refers to an object, usually near the end of its lifetime (so that its resources may be moved, for example). An xvalue is the result of certain kinds of expressions involving rvalue references (8.3.2).

The bold above has been added by me. The standard further says:

An rvalue (so called, historically, because rvalues could appear on the right-hand side of an assignment expression) is an xvalue, a temporary object (12.2) or subobject thereof, or a value that is not associated with an object.

So you only get an xvalue when you are playing around with 'certain kinds of expressions involving rvalue references'. Otherwise your temporary objects are just that - temporary objects.

quantum
  • 3,672
  • 29
  • 51