Boost logo

Boost :

Subject: Re: [boost] Range Adapters (map_keys, map_values) cause undefined behavior (segv, etc) when applied to R-Values, especially in the context of BOOST_FOREACH
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2014-01-29 20:41:00


Hi Igor, This is a known issue: see https://svn.boost.org/trac/boost/ticket/7630. (That bug talks about C++11 range-based for loops, but the issue with BOOST_FOREACH is the same). I'm not sure what the status of this bug is. Jeffrey Yasskin posted a patch to that bug which I reviewed over email, but I haven't heard from him about it since. Note that if you use C++11, a workaround is to use boost::for_each with a lambda instead, so   BOOST_FOREACH(SomeType v, range_rvalue | adaptor)   {       statements   } turns into     boost::for_each(range_rvalue | adaptor, [&](SomeType v)   {       statements   }); Since the temporary lives until the end of the statement, and the whole loop is contained within the statement, there is no more undefined behaviour. Regards, Nate


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk