13
#include <vector>

using namespace std;

struct A
{
    vector<int> coll;
};

void f(const vector<int>&){}
void f(vector<int>&&){}

int main()
{
    f(A().coll); // Is "A().coll" an xvalue? 
}

Does C++11 guarantee f(A().coll) will call void f(vector<int>&&)?

xmllmx
  • 39,765
  • 26
  • 162
  • 323
  • Highly related: http://stackoverflow.com/questions/35947296/about-binding-a-const-reference-to-a-sub-object-of-a-temporary – NathanOliver Feb 24 '17 at 17:01
  • [GCC-compiled Ideone.com](http://ideone.com/z9lpCD) seems to feel that `coll` is an xvalue. – Xirema Feb 24 '17 at 17:02

1 Answers1

9

Yes. C++14 standard, §5.2.5/4.2, given E1.E2:

If E2 is a non-static data member and the type of E1 is “cq1 vq1 X”, and the type of E2 is “cq2 vq2 T”, the expression designates the named member of the object designated by the first expression. If E1 is an lvalue, then E1.E2 is an lvalue; otherwise E1.E2 is an xvalue.

Pedantically, originally C++11 classified this as a prvalue, but such classification was meaningless so it was changed. If the change was applied by a defect report, though, then it's retroactive — the published C++11 standard document N3290 is wrong and the C++14 document defines C++11 instead. That's likely to be the case, as otherwise would require compilers to implement a subtle difference in behavior between -std=c++11 and -std=c++14. I'm lazy to search through DRs right now.

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421
  • 3
    It was changed in 2013, see https://github.com/cplusplus/draft/commit/728faf012696b81f906af77a1b22a8996dd7fa22 to resolve CWG616: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#616 – TBBle Feb 25 '17 at 00:37