c++ - Does this cause undefined behavior? -
address sanitizer 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. foreach happening on reference struct has been created foo call, , gone out of scope after being passed through bar()
Comments
Post a Comment