[Boost-bugs] [Boost C++ Libraries] #13357: boost::iterator_range<boost::counting_iterator<uint64_t>>::back() returns reference to temporary

Subject: [Boost-bugs] [Boost C++ Libraries] #13357: boost::iterator_range<boost::counting_iterator<uint64_t>>::back() returns reference to temporary
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-12-22 14:00:47


#13357: boost::iterator_range<boost::counting_iterator<uint64_t>>::back() returns
reference to temporary
--------------------------------------+-------------------------
 Reporter: MikoÅ‚aj Milej <mmilej@…> | Owner: Neil Groves
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: range
  Version: Boost 1.61.0 | Severity: Problem
 Keywords: |
--------------------------------------+-------------------------
 boost::iterator_range<boost::counting_iterator<uint64_t>>::back() returns
 reference to temporary

 it's created by

 {{{
 using RangeRawType = std::uint64_t;

 inline Range makeRange(
     RangeRawType begin,
     RangeRawType end = std::numeric_limits<RangeRawType>::max())
 {
     return boost::counting_range<RangeRawType>(begin, end);
 }
 }}}

 After investigation code of back() it probably returns reference to
 temporary value:

 {{{
     reference back() const
     {
         BOOST_ASSERT(!this->empty());
         return *boost::prior(this->m_End);
     }
 }}}

 So it returns just a junk (or rather this reference points to some random
 data).

 Code is the same in the newest boost (1.66 at time of writing).

-- 
Ticket URL: <https://svn.boost.org/trac10/boost/ticket/13357>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-12-22 14:07:49 UTC