Do rvalue references allow dangling references?

Do rvalue references allow dangling references? If you meant “Is it possible to create dangling rvalue references” then the answer is yes. Your example, however, string middle_name () { return “Jaan”; } int main() { string&& nodanger = middle_name(); // OK. // The life-time of the temporary is extended // to the life-time of the … Read more

In C++, what categories (lvalue, rvalue, xvalue, etc.) can expressions that produce temporaries of class type fall into?

Every expression is one, and only one, of: lvalue xvalue prvalue The union of expressions that are lvalues and xvalues are known collectively as glvalues. The union of expressions that are xvalues and prvalues are known collectively as rvalues. Thus xvalue expressions are known both as glvalues and rvalues. The handy diagram found in Alf‘s … Read more

Taking the address of a temporary object

The word “shall” in the standard language means a strict requirement. So, yes, your code is ill-formed (it is an error) because it attempts to apply address-of operator to a non-lvalue. However, the problem here is not an attempt of taking address of a temporary. The problem is, again, taking address of a non-lvalue. Temporary … Read more