Address sanitizer is complaining.
struct X
{
iterator begin();
iterator end();
};
X foo();
const X& bar(const X& x)
{
return x;
}
BOOST_FOREACH(const auto& xitem, bar(foo()))
{
//use xitem
}
Yes. The FOREACH is happening on a reference to a struct which has been created by the foo call, and gone out of scope after being passed through to bar()