Subject: Re: [Boost-bugs] [Boost C++ Libraries] #11609: circular_buffer erroneously invalidates reverse_iterator at pop_back in debug mode
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-09-02 17:54:42
#11609: circular_buffer erroneously invalidates reverse_iterator at pop_back in
debug mode
-----------------------------------+-----------------------------
Reporter: christian.stimming@⦠| Owner: jano_gaspar
Type: Bugs | Status: new
Milestone: To Be Determined | Component: circular_buffer
Version: Boost 1.57.0 | Severity: Problem
Resolution: | Keywords:
-----------------------------------+-----------------------------
Changes (by viboes):
* owner: => jano_gaspar
* component: None => circular_buffer
Old description:
> The circular_buffer container offers reverse iterators. Using one so that
> it points to the second-to-last element would in theory allow to
> pop_back() the last element without causing problems with that iterator.
> However, apparently pop_back() invalidates those reverse iterators even
> though they wouldn't cause problems, as if the debug_iterator_registry in
> boost/circular_buffer/debug.hpp is working correctly only for forward
> iterators but not for backward iterators.
>
> Example code that works fine without debug mode, but will run into a
> failed assertion in debug mode:
>
> #define BOOST_CB_ENABLE_DEBUG
> #include <boost/circular_buffer.hpp>
> #include <iostream>
> int main(int /*argc*/, char** /*argv*/) {
> typedef boost::circular_buffer<int> CircBuffer;
> CircBuffer testBuffer(2);
> testBuffer.push_back(4);
> testBuffer.push_back(8);
>
> CircBuffer::const_reverse_iterator bufIter = testBuffer.rbegin();
> std::cout << "element at rbegin=" << *bufIter << std::endl; //
> prints "=8" correctly
> ++bufIter;
> std::cout << "element after ++=" << *bufIter << std::endl; //
> prints "=4" correctly
> testBuffer.pop_back();
> std::cout << "elem=" << *bufIter << std::endl; // ERROR: Causes
> "Assertion `is_valid(m_buff)' failed."
> }
New description:
The circular_buffer container offers reverse iterators. Using one so that
it points to the second-to-last element would in theory allow to
pop_back() the last element without causing problems with that iterator.
However, apparently pop_back() invalidates those reverse iterators even
though they wouldn't cause problems, as if the debug_iterator_registry in
boost/circular_buffer/debug.hpp is working correctly only for forward
iterators but not for backward iterators.
Example code that works fine without debug mode, but will run into a
failed assertion in debug mode:
{{{
#define BOOST_CB_ENABLE_DEBUG
#include <boost/circular_buffer.hpp>
#include <iostream>
int main(int /*argc*/, char** /*argv*/) {
typedef boost::circular_buffer<int> CircBuffer;
CircBuffer testBuffer(2);
testBuffer.push_back(4);
testBuffer.push_back(8);
CircBuffer::const_reverse_iterator bufIter = testBuffer.rbegin();
std::cout << "element at rbegin=" << *bufIter << std::endl; //
prints "=8" correctly
++bufIter;
std::cout << "element after ++=" << *bufIter << std::endl; //
prints "=4" correctly
testBuffer.pop_back();
std::cout << "elem=" << *bufIter << std::endl; // ERROR: Causes
"Assertion `is_valid(m_buff)' failed."
}
}}}
-- -- Ticket URL: <https://svn.boost.org/trac/boost/ticket/11609#comment:2> 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-02-16 18:50:18 UTC