[libcxx] r316914 - Fix PR#35119 : set_union misbehaves with move_iterators. Thanks to Denis Yaroshevskiy for both the bug report and the fix.
Marshall Clow via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 30 08:50:00 PDT 2017
Author: marshall
Date: Mon Oct 30 08:50:00 2017
New Revision: 316914
URL: http://llvm.org/viewvc/llvm-project?rev=316914&view=rev
Log:
Fix PR#35119 : set_union misbehaves with move_iterators. Thanks to Denis Yaroshevskiy for both the bug report and the fix.
Added:
libcxx/trunk/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union_move.pass.cpp
Modified:
libcxx/trunk/include/algorithm
Modified: libcxx/trunk/include/algorithm
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=316914&r1=316913&r2=316914&view=diff
==============================================================================
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Mon Oct 30 08:50:00 2017
@@ -5547,9 +5547,9 @@ __set_union(_InputIterator1 __first1, _I
}
else
{
- *__result = *__first1;
if (!__comp(*__first1, *__first2))
++__first2;
+ *__result = *__first1;
++__first1;
}
}
Added: libcxx/trunk/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union_move.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union_move.pass.cpp?rev=316914&view=auto
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union_move.pass.cpp (added)
+++ libcxx/trunk/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union_move.pass.cpp Mon Oct 30 08:50:00 2017
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <algorithm>
+
+// template<InputIterator InIter1, InputIterator InIter2, typename OutIter,
+// CopyConstructible Compare>
+// requires OutputIterator<OutIter, InIter1::reference>
+// && OutputIterator<OutIter, InIter2::reference>
+// && Predicate<Compare, InIter1::value_type, InIter2::value_type>
+// && Predicate<Compare, InIter2::value_type, InIter1::value_type>
+// OutIter
+// set_union(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2,
+// OutIter result, Compare comp);
+
+#include <algorithm>
+#include <cassert>
+#include <iterator>
+#include <vector>
+
+#include "MoveOnly.h"
+
+
+int main()
+{
+ std::vector<MoveOnly> lhs, rhs;
+ lhs.push_back(MoveOnly(2));
+ rhs.push_back(MoveOnly(2));
+
+ std::vector<MoveOnly> res;
+ std::set_union(std::make_move_iterator(lhs.begin()),
+ std::make_move_iterator(lhs.end()),
+ std::make_move_iterator(rhs.begin()),
+ std::make_move_iterator(rhs.end()), std::back_inserter(res));
+
+ assert(res.size() == 1);
+ assert(res[0].get() == 2);
+}
More information about the cfe-commits
mailing list