Opened 7 years ago
Last modified 7 years ago
#11609 new Bugs
circular_buffer erroneously invalidates reverse_iterator at pop_back in debug mode
Reported by: | Owned by: | Jan Gaspar | |
---|---|---|---|
Milestone: | To Be Determined | Component: | circular_buffer |
Version: | Boost 1.57.0 | Severity: | Problem |
Keywords: | Cc: |
Description (last modified by )
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." }
Change History (2)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
Component: | None → circular_buffer |
---|---|
Description: | modified (diff) |
Owner: | set to |
Sorry, here the code again in readable form: