Fixes #171 ("deque::clear() uses undefined behaviour")

This commit is contained in:
Ion Gaztañaga
2020-11-10 10:08:03 +01:00
parent 220ab147ad
commit 2a458005d9
2 changed files with 19 additions and 14 deletions

View File

@@ -1341,6 +1341,8 @@ use [*Boost.Container]? There are several reasons for that:
[section:release_notes_boost_1_76_00 Boost 1.76 Release] [section:release_notes_boost_1_76_00 Boost 1.76 Release]
* Added [[no-discard]] attribute in all containers to catch bugs related to unused return values. * Added [[no-discard]] attribute in all containers to catch bugs related to unused return values.
* Fixed bugs/issues:
* [@https://github.com/boostorg/container/issues/171 GitHub #171: ['"deque::clear() uses undefined behaviour"]].
[endsect] [endsect]

View File

@@ -1843,6 +1843,8 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
//! <b>Complexity</b>: Linear to the number of elements in the deque. //! <b>Complexity</b>: Linear to the number of elements in the deque.
void clear() BOOST_NOEXCEPT_OR_NOTHROW void clear() BOOST_NOEXCEPT_OR_NOTHROW
{ {
if (this->members_.m_finish != this->members_.m_start) {
for (index_pointer node = this->members_.m_start.m_node + 1; for (index_pointer node = this->members_.m_start.m_node + 1;
node < this->members_.m_finish.m_node; node < this->members_.m_finish.m_node;
++node) { ++node) {
@@ -1860,6 +1862,7 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
this->members_.m_finish = this->members_.m_start; this->members_.m_finish = this->members_.m_start;
} }
}
//! <b>Effects</b>: Returns true if x and y are equal //! <b>Effects</b>: Returns true if x and y are equal
//! //!