mardi 27 octobre 2015

Does a reference declaration introduce a new name for the referent?

In this question we've learnt that RVO cannot be applied to an expression like p.first.

In comments it was also suggested that RVO is generally not applied to an expression like r after a declaration like auto& r = p.first. It is less clear whether the standard mandates this behaviour.

in a return statement in a function with a class return type, when the expression is the name of a non-volatile automatic object (other than a function parameter or a variable introduced by the exception-declaration of a handler ([except.handle])) with the same type (ignoring cv-qualification) as the function return type, the copy/move operation can be omitted by constructing the automatic object directly into the function's return value

In the following code, is r a name of the object also known as o, to the extent that RVO is permissible when it forms the expression in a return statement?

int o = 42;
int& r = o;

Aucun commentaire:

Enregistrer un commentaire