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: Paolo Carlini <paolo dot carlini at oracle dot com>
- Cc: François Dumont <frs dot dumont at gmail dot com>, libstdc++ at gcc dot gnu dot org, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 29 Jun 2016 11:07:04 +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> <20160629085745 dot GG7722 at redhat dot com> <57739648 dot 7020400 at oracle dot com>
On 29/06/16 11:35 +0200, Paolo Carlini wrote:
Hi,
On 29/06/2016 10:57, Jonathan Wakely wrote:
On 28/06/16 21:59 +0200, François Dumont wrote:
+ if (_M_data_ptr(__position.base()) <= __ptr
+ && __ptr < _M_data_ptr(this->_M_impl._M_finish - 1))
This is undefined behaviour. If the object is not contained in the
vector then you can't compare its address to addresses within the
vector.
Uhm, would that be true also if the code used std::less? Aren't we
doing something like that in std::basic_string under the assumption
(Nathan?) that it would not be the case? Or maybe I'm misreading the
code (admittedly I didn't follow in detail the whole exchange)
Yes, it's OK if you use std::less. In general there's no guarantee
that std::less<T*> defines the same order as operator<(T*, T*), but in
our implementation it does.
I'd still prefer to keep a correctness fix and a potentially risky
optimisation in separate commits.