[LLVMdev] MS VS2010 std implementation: "Cannot assign iterators to two different blocks!"

Michael Spencer bigcheesegs at gmail.com
Thu Oct 21 07:52:44 PDT 2010


On Mon, Oct 4, 2010 at 9:52 PM, Bob Floyd <bobfloyd at comcast.net> wrote:
> When using MS VS2010 there is an issue with std:
>
>
>
> `SuccIterator` implements a partial assignment operator:
>
>
>
> inline const _Self &operator=(const _Self &I) {
>
>     assert(Term == I.Term &&"Cannot assign iterators to two different
> blocks!");
>
>     idx = I.idx;
>
>     return *this;
>
>     }
>
>
>
> For copy construction, MS VS2010 std reserves the right, and sometimes
> calls,
>
> a method to reverse elements which does so by swap:
>
>
>
>  template<class _Ty> inline
>
>  void swap(_Ty& _Left, _Ty& _Right)
>
>  {             // exchange values stored at _Left and _Right
>
>    _Ty _Tmp = _Move(_Left);

This uses the compiler generated default copy constructor which does
an element by element copy.

>    _Left = _Move(_Right); <<<<<<<<<<<<< Needs FULL assignment operator!!!!

Given that SuccIterator does not implement move semantics, we can
basically remove all the _Move's here, they just turn into
assignments. Thus _Left and _Right are both fully constructed.
_Left.Term == _Right.Term is true if it was true before swap.

>    _Right = _Move(_Tmp);
>
>  }
>
>
>
> When `_Ty` is `SuccIterator const` the assert "Cannot assign iterators to
> two different blocks!" can fail.
>
>
>
> Can this be a workaround:
>
>
>
> inline const _Self &operator=(const _Self &I) {
>
>   new (this) _Self(I);
>
>   return *this;
>
> }
>
>
>
> The larger question is can both the assert be preserved and swap satisfied?

I believe this is an error in your code. Are you 100% sure that
_Left.Term == _Right.Term before swap is called?

- Michael Spencer




More information about the llvm-dev mailing list