What happens when a const reference to a a member of a temporary object is returned; What is the lifetime of that object;
E.g.
struct temp
{
T m_mine;
static temp make()
{
return temp();
}
};
T const & foo()
{
return temp::make().m_mine;
}
What is the behavior with c++98 and c++11?
The constness of the object or the referee type doesn't matter in this context: it's simply a return of a reference to an object that at that time has ceased to exist. Using the reference is then Undefined Behavior.
Likewise, if you bind a member reference to const, to an object, that does not prolong the life of the referee.
Object lifetime extension is only for the case of binding a local reference to an object, and only for the cases of reference to const
object or rvalue reference.
The example code as it was at the time I wrote this, has several problems. Please only post real code (to the degree possible). And it should be pasted, not retyped.
(Also, since there is now at least 2 answers referring to the problems of the code, it's too late to correct it without possibly changing the context of the answers and thereby invalidating them. So it's important to get the code correct in the original posting. Worth keeping in mind for next SO question.)