Improve insert/emplace robustness to self insertion
Paolo Carlini
paolo.carlini@oracle.com
Wed Jun 29 10:15:00 GMT 2016
Hi,
On 29/06/2016 12:07, Jonathan Wakely wrote:
> 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.
Ah Ok, excellent.
> I'd still prefer to keep a correctness fix and a potentially risky
> optimisation in separate commits.
Definitely. Maybe with an additional comment too!
Paolo.
More information about the Libstdc++
mailing list