value-categories

Lifetime extension, prvalues and xvalues

纵饮孤独 提交于 2020-01-21 05:37:25
问题 Following the well accepted answer to this question Do rvalue references allow dangling references? It would seem that xvalues do not have their lifetime extended when assigned to a rvalue reference lvalue like in the question. However when I do this #include <iostream> using namespace std; class Something { public: Something() { cout << "Something()" << endl; } Something(const Something&) { cout << "Something(const Something&)" << endl; } Something(Something&&) { cout << "Something(Something

Rvalues, lvalues and formal definitions

独自空忆成欢 提交于 2020-01-12 00:53:28
问题 People are confused when they hear that in int&& x x has rvalue reference type, but x is an lvalue. Misunderstanding stems from the fact that identifiers and expressions are different things, and so are types and value categories. Moreover, types of expressions are "adjusted prior to any further analysis", and the words "rvalue" and "lvalue" can appear both in type name and in value category name. I want to clarify formal definitions. Suppose we have a function: 1 | void f(int&& x) { 2 | ...

Value category of conditional operator

老子叫甜甜 提交于 2019-12-23 12:58:28
问题 Consider the following code: int x; int& f() { return x ? x : throw 0; } With gcc version 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04) I get the following compilation error: cannot bind non-const lvalue reference of type ‘int&’ to an rvalue of type ‘int’ Note that this compiles just fine in clang. Here is (what I believe to be) the relevant statement from the standard: N4659 [8.16.2.1] (Conditional Operator): The second or the third operand (but not both) is a (possibly parenthesized) throw

Is cppreference using the term “[Object's] identity” is two different meanings for c++11 and for c++17?

二次信任 提交于 2019-12-08 19:44:13
问题 I thought I've managed to fully understand (with the help of other SO questions, thanks) the C++17's change regarding value categories, but now I've noticed this problem which suggests I don't really understand them. In C++11, there was a "has identity / can be moved from" interpretation of value categories and the definition of what "identity" means is still present in cppreference: has identity: it's possible to determine whether the expression refers to the same entity as another