I think this is a problem with your expectations
The code in your main function is evalualated equivalent like this.
((std::cout << "return: ") << bar()) << std::endl;
The << operators are evaluated left to right one at a time. Just as they would be in the case of something like “foo() + bar() + baz()”
The << operator for cout prints and then return a reference to its left hand side so that multiple << can be chained together. Due to that, another way to write this is:
std::cout << "return: ";
std::cout << bar();
std::cout << std::endl;