- list's
end()
returns a copy of the past-the-end iterator, right? - Therefore,
list.end()
is an rvalue, right? - the -- operator-function overloaded for list iterator takes a non-const reference, right?
- you can't bind rvalues to non-const references, right?
So how come does
std::list<int> lst;
// ...
--l.end();`
compile?
As correctly pointed out, my third point is not necessarily right. But then how about this code which also compiles?
struct A{};
void f(A&)
{
}
A a()
{
return A();
}
int main()
{
f(a());
}