This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Improve insert/emplace robustness to self insertion
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: François Dumont <frs dot dumont at gmail dot com>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 29 Jun 2016 10:10:56 +0100
- Subject: Re: Improve insert/emplace robustness to self insertion
- Authentication-results: sourceware.org; auth=none
- References: <20160615101511 dot GN11538 at redhat dot com> <20160615103424 dot GO11538 at redhat dot com> <5762FDAC dot 5000802 at gmail dot com> <20160616202106 dot GB11538 at redhat dot com> <57665607 dot 7080004 at gmail dot com> <20160620074230 dot GB6159 at redhat dot com> <5772D70D dot 4020103 at gmail dot com>
On 28/06/16 21:59 +0200, François Dumont wrote:
@@ -303,16 +301,20 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
emplace(const_iterator __position, _Args&&... __args)
{
const size_type __n = __position - begin();
It looks like this should use __position - cbegin(), to avoid an
implicit conversion from iterator to const_iterator, and ...
- if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
- && __position == end())
- {
- _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
- std::forward<_Args>(__args)...);
- ++this->_M_impl._M_finish;
- }
+ if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
+ if (__position == end())
This could be __position == cend(), and ...
+ {
+ _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
+ std::forward<_Args>(__args)...);
+ ++this->_M_impl._M_finish;
+ }
+ else
+ _M_insert_aux(begin() + (__position - cbegin()),
This could use __n, and ...
+ std::forward<_Args>(__args)...);
else
- _M_insert_aux(begin() + (__position - cbegin()),
- std::forward<_Args>(__args)...);
+ _M_realloc_insert_aux(begin() + (__position - cbegin()),
This could also use __n.
+ std::forward<_Args>(__args)...);
+
return iterator(this->_M_impl._M_start + __n);
}