Does Visual C++ not perform return-value optimization?
#include
struct Foo { ~Foo() { printf(\"Destructing...\\n\"); } };
Foo foo() { return Foo()
When I test with this:
#include <iostream>
struct Foo {
Foo(Foo const &r) { std::cout << "Copying...\n"; }
~Foo() { std::cout << "Destructing...\n"; }
Foo() {}
};
Foo foo() { return Foo(); }
int main() { Foo f = foo(); }
...the output I get is:
Destructing...
No invocation of the copy constructor, and only one of the destructor.