Let's say we have this situation
std::string v_1()
{
return "name";
}
std::string test = v_1();
Is RVO applied here? I think that the answer is no, because one the rules to apply RVO is: "If a function returns a class type by value, and the return statement's expression is the name of a non-volatile object with automatic storage duration, which isn't the function parameter, or a catch clause parameter, and which has the same type (ignoring top-level cv-qualification) as the return type of the function, then copy/move is omitted" And in this situation the object returned does not have the same type of the return type of the function, but I'm not 100% that RVO is not applied here.
Thank you very much.
PS. On this talk https://www.youtube.com/watch?v=AKtHxKJRwp4 (minute 40, second 18) Stephan, from Microsoft, talks about a situation where RVO cannot be applied because the return type of the function is different than the type of the returned object (in his example a tuple vs a pair). I think that the same principle applies here.