http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59603
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> --- This patch avoids the self-move: index 4c6ca8a..6ce2d21 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -4430,7 +4430,12 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO if (__first != __last) for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i) - std::iter_swap(__i, __first + (std::rand() % ((__i - __first) + 1))); + { + int __offset = std::rand() % ((__i - __first) + 1); + _RandomAccessIterator __j = __first + __offset; + if (__i != __j) + std::iter_swap(__i, __j); + } } /** But I'm not sure whether this is a real bug, or types used with random_shuffle should be safe against self-move (which means they can't use an implicit move ctor if they have types that are not safe against self-move, which includes most std::lib types).