This is a question about C++ specs on object destruction vs Return-Value-Optimization.
Can I expect RVO return the right value before std::unique_ptr<> cleanup?
Foo Bar()
{
std::unique_ptr<Foo> ptr = new Foo();
return *ptr;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It will return the right value with or without RVO (and there is no RVO in this case). The function returns a concrete
Foo, so*ptrwill be copied into the return value before destruction of the pointer.That means,
is similar to (unwrapping the unique_ptr to be more explicit)