Let's consider the next sample:
struct big_type {};
// Return by copy
auto factory() { return big_type{}; }
void any_scope_or_function() {
big_type&& lifetime_extended = factory();
}
Under the assumption RVO is forbidden or not present at all and in any manner, will or can big_type()
be copied? Or will the reference be directly bound to the temporary constructed within the return
statement?
I want to be sure the big_type
destructor is called only once when any_scope_or_function
ends.
I use C++14, in case some behaviour has changed between standard's versions.