Boost C++ Libraries: Ticket #13357: boost::iterator_range<boost::counting_iterator<uint64_t>>::back() returns reference to temporary https://svn.boost.org/trac10/ticket/13357 <p> boost::iterator_range&lt;boost::counting_iterator&lt;uint64_t&gt;&gt;::back() returns reference to temporary </p> <p> it's created by </p> <pre class="wiki">using RangeRawType = std::uint64_t; inline Range makeRange( RangeRawType begin, RangeRawType end = std::numeric_limits&lt;RangeRawType&gt;::max()) { return boost::counting_range&lt;RangeRawType&gt;(begin, end); } </pre><p> After investigation code of back() it probably returns reference to temporary value: </p> <pre class="wiki"> reference back() const { BOOST_ASSERT(!this-&gt;empty()); return *boost::prior(this-&gt;m_End); } </pre><p> So it returns just a junk (or rather this reference points to some random data). </p> <p> Code is the same in the newest boost (1.66 at time of writing). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13357 Trac 1.4.3 Mikołaj Milej <mmilej@…> Fri, 22 Dec 2017 14:02:04 GMT keywords set https://svn.boost.org/trac10/ticket/13357#comment:1 https://svn.boost.org/trac10/ticket/13357#comment:1 <ul> <li><strong>keywords</strong> range added </li> </ul> Ticket