Is, returning an lvalue reference to *this
, allowed when *this
is an rvalue?
#include <iostream>
#include <string>
using namespace std;
class A {
public:
A& f() {
return *this;
}
string val() const {
return "works";
}
};
int main() {
cout << A{}.f().val();
}
Is there ANY scenario where the value returned by f()
will be a dangling reference at some point?
Does calling f()
prolongs the lifetime of the caller if this is an rvalue like in example?