This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Improve insert/emplace robustness to self insertion


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.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]