Consider the following C++ code.
struct foo { std::string value; }
inline foo bar() { return { "42" }; }
Now imagine I have a function that uses bar() in the following way.
std::string my_func()
{
const auto &x = bar();
return x.value;
}
Does this leak memory Because my_func only holds a reference to x? Or does x still get cleaned up after my_func terminates?
I know this is not how references are supposed to be used. But I just realized this compiles fine and wondered what the semantics of it are.