diff options
Diffstat (limited to 'gcc-4.9/libstdc++-v3/include/bits/stl_bvector.h')
-rw-r--r-- | gcc-4.9/libstdc++-v3/include/bits/stl_bvector.h | 245 |
1 files changed, 225 insertions, 20 deletions
diff --git a/gcc-4.9/libstdc++-v3/include/bits/stl_bvector.h b/gcc-4.9/libstdc++-v3/include/bits/stl_bvector.h index 996eb1a8d..86375cb9b 100644 --- a/gcc-4.9/libstdc++-v3/include/bits/stl_bvector.h +++ b/gcc-4.9/libstdc++-v3/include/bits/stl_bvector.h @@ -471,11 +471,31 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER #endif ~_Bvector_base() - { this->_M_deallocate(); } + { + this->_M_deallocate(); +#if __google_stl_debug_bvector + __builtin_memset(this, 0xcd, sizeof(*this)); +#endif + } protected: _Bvector_impl _M_impl; +#if __google_stl_debug_bvector + bool _M_is_valid() const + { + return (this->_M_impl._M_start._M_p == 0 + && this->_M_impl._M_finish._M_p == 0 + && this->_M_impl._M_end_of_storage == 0) + || (this->_M_impl._M_start._M_p <= this->_M_impl._M_finish._M_p + && this->_M_impl._M_finish._M_p <= this->_M_impl._M_end_of_storage + && (this->_M_impl._M_start._M_p < this->_M_impl._M_end_of_storage + || (this->_M_impl._M_start._M_p == this->_M_impl._M_end_of_storage + && this->_M_impl._M_start._M_offset == 0 + && this->_M_impl._M_finish._M_offset == 0))); + } +#endif + _Bit_type* _M_allocate(size_t __n) { return _M_impl.allocate(_S_nword(__n)); } @@ -631,6 +651,10 @@ template<typename _Alloc> vector& operator=(const vector& __x) { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("op=() on corrupt (dangling?) vector"); +#endif if (&__x == this) return *this; if (__x.size() > capacity()) @@ -647,6 +671,10 @@ template<typename _Alloc> vector& operator=(vector&& __x) { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("op=() on corrupt (dangling?) vector"); +#endif // NB: DR 1204. // NB: DR 675. this->clear(); @@ -668,19 +696,35 @@ template<typename _Alloc> // or not the type is an integer. void assign(size_type __n, const bool& __x) - { _M_fill_assign(__n, __x); } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("assign() on corrupt (dangling?) vector"); +#endif + _M_fill_assign(__n, __x); + } #if __cplusplus >= 201103L template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>> void assign(_InputIterator __first, _InputIterator __last) - { _M_assign_dispatch(__first, __last, __false_type()); } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("assign() on corrupt (dangling?) vector"); +#endif + _M_assign_dispatch(__first, __last, __false_type()); + } #else template<typename _InputIterator> void assign(_InputIterator __first, _InputIterator __last) { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("assign() on corrupt (dangling?) vector"); +#endif typedef typename std::__is_integer<_InputIterator>::__type _Integral; _M_assign_dispatch(__first, __last, _Integral()); } @@ -694,19 +738,43 @@ template<typename _Alloc> iterator begin() _GLIBCXX_NOEXCEPT - { return this->_M_impl._M_start; } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("begin() on corrupt (dangling?) vector"); +#endif + return this->_M_impl._M_start; + } const_iterator begin() const _GLIBCXX_NOEXCEPT - { return this->_M_impl._M_start; } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("begin() on corrupt (dangling?) vector"); +#endif + return this->_M_impl._M_start; + } iterator end() _GLIBCXX_NOEXCEPT - { return this->_M_impl._M_finish; } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("end() on corrupt (dangling?) vector"); +#endif + return this->_M_impl._M_finish; + } const_iterator end() const _GLIBCXX_NOEXCEPT - { return this->_M_impl._M_finish; } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("end() on corrupt (dangling?) vector"); +#endif + return this->_M_impl._M_finish; + } reverse_iterator rbegin() _GLIBCXX_NOEXCEPT @@ -727,11 +795,23 @@ template<typename _Alloc> #if __cplusplus >= 201103L const_iterator cbegin() const noexcept - { return this->_M_impl._M_start; } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("cbegin() on corrupt (dangling?) vector"); +#endif + return this->_M_impl._M_start; + } const_iterator cend() const noexcept - { return this->_M_impl._M_finish; } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("cend() on corrupt (dangling?) vector"); +#endif + return this->_M_impl._M_finish; + } const_reverse_iterator crbegin() const noexcept @@ -749,6 +829,10 @@ template<typename _Alloc> size_type max_size() const _GLIBCXX_NOEXCEPT { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("max_size() on corrupt (dangling?) vector"); +#endif const size_type __isize = __gnu_cxx::__numeric_traits<difference_type>::__max - int(_S_word_bit) + 1; @@ -769,6 +853,11 @@ template<typename _Alloc> reference operator[](size_type __n) { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("operator[] on corrupt (dangling?) vector"); + _M_range_check(__n); +#endif return *iterator(this->_M_impl._M_start._M_p + __n / int(_S_word_bit), __n % int(_S_word_bit)); } @@ -776,6 +865,11 @@ template<typename _Alloc> const_reference operator[](size_type __n) const { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("operator[] on corrupt (dangling?) vector"); + _M_range_check(__n); +#endif return *const_iterator(this->_M_impl._M_start._M_p + __n / int(_S_word_bit), __n % int(_S_word_bit)); } @@ -794,11 +888,21 @@ template<typename _Alloc> public: reference at(size_type __n) - { _M_range_check(__n); return (*this)[__n]; } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("at() on corrupt (dangling?) vector"); +#endif + _M_range_check(__n); return (*this)[__n]; } const_reference at(size_type __n) const - { _M_range_check(__n); return (*this)[__n]; } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("at() on corrupt (dangling?) vector"); +#endif + _M_range_check(__n); return (*this)[__n]; } void reserve(size_type __n) @@ -811,19 +915,47 @@ template<typename _Alloc> reference front() - { return *begin(); } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("front() on corrupt (dangling?) vector"); + _M_range_check(0); +#endif + return *begin(); + } const_reference front() const - { return *begin(); } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("front() on corrupt (dangling?) vector"); + _M_range_check(0); +#endif + return *begin(); + } reference back() - { return *(end() - 1); } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("back() on corrupt (dangling?) vector"); + _M_range_check(0); +#endif + return *(end() - 1); + } const_reference back() const - { return *(end() - 1); } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("back() on corrupt (dangling?) vector"); + _M_range_check(0); +#endif + return *(end() - 1); + } // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 464. Suggestion for new member functions in standard containers. @@ -836,6 +968,10 @@ template<typename _Alloc> void push_back(bool __x) { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("push_back() on corrupt (dangling?) vector"); +#endif if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage) *this->_M_impl._M_finish++ = __x; else @@ -845,6 +981,10 @@ template<typename _Alloc> void swap(vector& __x) { +#if __google_stl_debug_bvector + if (!this->_M_is_valid() || !__x._M_is_valid()) + __throw_logic_error("swap() on corrupt (dangling?) vector"); +#endif std::swap(this->_M_impl._M_start, __x._M_impl._M_start); std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish); std::swap(this->_M_impl._M_end_of_storage, @@ -872,6 +1012,12 @@ template<typename _Alloc> insert(iterator __position, const bool& __x = bool()) #endif { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("insert() on corrupt (dangling?) vector"); + if (__position < this->begin() || __position > this->end()) + __throw_logic_error("insert() at invalid position"); +#endif const difference_type __n = __position - begin(); if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage && __position == end()) @@ -888,6 +1034,12 @@ template<typename _Alloc> insert(const_iterator __position, _InputIterator __first, _InputIterator __last) { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("insert() on corrupt (dangling?) vector"); + if (__position < this->begin() || __position > this->end()) + __throw_logic_error("insert() at invalid position"); +#endif difference_type __offset = __position - cbegin(); _M_insert_dispatch(__position._M_const_cast(), __first, __last, __false_type()); @@ -899,6 +1051,12 @@ template<typename _Alloc> insert(iterator __position, _InputIterator __first, _InputIterator __last) { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("insert() on corrupt (dangling?) vector"); + if (__position < this->begin() || __position > this->end()) + __throw_logic_error("insert() at invalid position"); +#endif typedef typename std::__is_integer<_InputIterator>::__type _Integral; _M_insert_dispatch(__position, __first, __last, _Integral()); } @@ -908,6 +1066,12 @@ template<typename _Alloc> iterator insert(const_iterator __position, size_type __n, const bool& __x) { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("insert() on corrupt (dangling?) vector"); + if (__position < this->begin() || __position > this->end()) + __throw_logic_error("insert() at invalid position"); +#endif difference_type __offset = __position - cbegin(); _M_fill_insert(__position._M_const_cast(), __n, __x); return begin() + __offset; @@ -915,7 +1079,15 @@ template<typename _Alloc> #else void insert(iterator __position, size_type __n, const bool& __x) - { _M_fill_insert(__position, __n, __x); } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("insert() on corrupt (dangling?) vector"); + if (__position < this->begin() || __position > this->end()) + __throw_logic_error("insert() at invalid position"); +#endif + _M_fill_insert(__position, __n, __x); + } #endif #if __cplusplus >= 201103L @@ -926,7 +1098,14 @@ template<typename _Alloc> void pop_back() - { --this->_M_impl._M_finish; } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("pop_back() on corrupt (dangling?) vector"); + _M_range_check(0); +#endif + --this->_M_impl._M_finish; + } iterator #if __cplusplus >= 201103L @@ -934,7 +1113,15 @@ template<typename _Alloc> #else erase(iterator __position) #endif - { return _M_erase(__position._M_const_cast()); } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("erase() on corrupt (dangling?) vector"); + if (__position < this->begin() || __position >= this->end()) + __throw_logic_error("erase() at invalid position"); +#endif + return _M_erase(__position._M_const_cast()); + } iterator #if __cplusplus >= 201103L @@ -942,7 +1129,15 @@ template<typename _Alloc> #else erase(iterator __first, iterator __last) #endif - { return _M_erase(__first._M_const_cast(), __last._M_const_cast()); } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("erase() on corrupt (dangling?) vector"); + if (__first < this->begin() || __first > __last || __last > this->end()) + __throw_logic_error("erase() invalid range"); +#endif + return _M_erase(__first._M_const_cast(), __last._M_const_cast()); + } void resize(size_type __new_size, bool __x = bool()) @@ -956,12 +1151,22 @@ template<typename _Alloc> #if __cplusplus >= 201103L void shrink_to_fit() - { _M_shrink_to_fit(); } + { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("shrink_to_fit() on corrupt (dangling?) vector"); +#endif + _M_shrink_to_fit(); + } #endif void flip() _GLIBCXX_NOEXCEPT { +#if __google_stl_debug_bvector + if (!this->_M_is_valid()) + __throw_logic_error("flip() on corrupt (dangling?) vector"); +#endif for (_Bit_type * __p = this->_M_impl._M_start._M_p; __p != this->_M_impl._M_end_of_storage; ++__p) *__p = ~*__p; |