[libcxx] r321851 - Fix incorrect handling of move-only types in transform_reduce iter iter iter init, and add test.

Billy Robert O'Neal III via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 4 17:31:58 PST 2018


Author: bion
Date: Thu Jan  4 17:31:57 2018
New Revision: 321851

URL: http://llvm.org/viewvc/llvm-project?rev=321851&view=rev
Log:
Fix incorrect handling of move-only types in transform_reduce iter iter iter init, and add test.

Modified:
    libcxx/trunk/include/numeric
    libcxx/trunk/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp

Modified: libcxx/trunk/include/numeric
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/numeric?rev=321851&r1=321850&r2=321851&view=diff
==============================================================================
--- libcxx/trunk/include/numeric (original)
+++ libcxx/trunk/include/numeric Thu Jan  4 17:31:57 2018
@@ -252,7 +252,7 @@ _Tp
 transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
                  _InputIterator2 __first2, _Tp __init)
 {
-    return _VSTD::transform_reduce(__first1, __last1, __first2, __init, 
+    return _VSTD::transform_reduce(__first1, __last1, __first2, _VSTD::move(__init),
                                    _VSTD::plus<>(), _VSTD::multiplies<>());
 }
 #endif

Modified: libcxx/trunk/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp?rev=321851&r1=321850&r2=321851&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp Thu Jan  4 17:31:57 2018
@@ -17,7 +17,9 @@
 
 #include <numeric>
 #include <cassert>
+#include <iterator>
 
+#include "MoveOnly.h"
 #include "test_iterators.h"
 
 template <class Iter1, class Iter2, class T>
@@ -56,6 +58,24 @@ void test_return_type()
                        decltype(std::transform_reduce(p, p, p, Init{}))> );
 }
 
+inline MoveOnly operator+(const MoveOnly& lhs, const MoveOnly& rhs)
+{
+    return MoveOnly{lhs.get() + rhs.get()};
+}
+
+inline MoveOnly operator*(const MoveOnly& lhs, const MoveOnly& rhs)
+{
+    return MoveOnly{lhs.get() * rhs.get()};
+}
+
+void test_move_only_types()
+{
+    MoveOnly ia[] = {{1}, {2}, {3}};
+    MoveOnly ib[] = {{1}, {2}, {3}};
+    assert(14 ==
+        std::transform_reduce(std::begin(ia), std::end(ia), std::begin(ib), MoveOnly{0}).get());
+}
+
 int main()
 {
     test_return_type<char, int>();
@@ -92,4 +112,6 @@ int main()
     test<const int*,       unsigned int *>();
     test<      int*, const unsigned int *>();
     test<      int*,       unsigned int *>();
+
+    test_move_only_types();
 }




More information about the cfe-commits mailing list