There exists code that relies on the fact that local automatic function variables are destroyed after the return value has been created, for example:
1) Unmangling the result of std::type_info::name
std::string demangle(const char* name)
{
int status = -4;
std::unique_ptr<char, void(*)(void*)> res {
abi::__cxa_demangle(name, NULL, NULL, &status),
std::free
};
return (status==0) ? res.get() : name;
}
2) Timing of scope-based lock guards and return values
class C {
mutable std::mutex _lock;
map<string,string> deep_member;
public:
auto get_big_lump()
{
std::unique_lock<std::mutex> lock(_lock);
return deep_member;
}
};
Where does the standard specify this order is guaranteed?