I wrote the following program and expected that the rvalue gotten from std::move()
would be destroyed right after it's used in the function call:
struct A
{
A(){ }
A(const A&){ std::cout << "A&" << std::endl; }
~A(){ std::cout << "~A()" << std::endl; }
A operator=(const A&){ std::cout << "operator=" << std::endl; return A();}
};
void foo(const A&&){ std::cout << "foo()" << std::endl; }
int main(){
const A& a = A();
foo(std::move(a)); //after evaluation the full-expression
//rvalue should have been destroyed
std::cout << "before ending the program" << std::endl;
}
But it was not. The following output was produced instead:
foo()
before ending the program
~A()
As said in the answer
rvalues denote temporary objects which are destroyed at the next semicolon
What did I get wrong?