Self move assignment debug check

François Dumont frs.dumont@gmail.com
Mon Nov 2 20:42:00 GMT 2015


On 16/09/2015 22:29, Jonathan Wakely wrote:
> On 16/09/15 21:37 +0200, François Dumont wrote:
>> On 14/09/2015 21:50, Jonathan Wakely wrote:
>>> On 14/09/15 20:27 +0200, François Dumont wrote:
>>>> diff --git a/libstdc++-v3/include/bits/stl_vector.h
>>>> b/libstdc++-v3/include/bits/stl_vector.h
>>>> index 305d446..89a9aec 100644
>>>> --- a/libstdc++-v3/include/bits/stl_vector.h
>>>> +++ b/libstdc++-v3/include/bits/stl_vector.h
>>>> @@ -449,6 +449,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
>>>>       vector&
>>>>       operator=(vector&& __x)
>>>> noexcept(_Alloc_traits::_S_nothrow_move())
>>>>       {
>>>> +    __glibcxx_assert(this != &__x);
>>>
>>> Please don't do this, it fails in valid programs. The standard needs
>>> to be fixed in this regard.
>>
>> The debug mode check should be removed too then.
>
> Yes.
>

    I had a look to the code of several move assignment operators. If
the plan is that it should be a no-op then they are not supporting
operation with self. Do you mean that those operators should be made
compatible so that debug check can be removed ?

    If so the simplest evolution would be to add:

if (this == &__x)
    return *this;

    Is it how the Standard is going to be adapted ?

François



More information about the Libstdc++ mailing list