libstdc++: Fix LWG issues 3389 and 3390
authorPatrick Palka <ppalka@redhat.com>
Tue, 11 Feb 2020 15:45:26 +0000 (10:45 -0500)
committerPatrick Palka <ppalka@redhat.com>
Wed, 12 Feb 2020 21:30:19 +0000 (16:30 -0500)
libstdc++-v3/ChangeLog:

LWG 3389 and LWG 3390
* include/bits/stl_iterator.h (move_move_iterator): Use std::move when
constructing the move_iterator with __i.
(counted_iterator::counted_iterator): Use std::move when initializing
M_current with __i.
* testsuite/24_iterators/counted_iterator/lwg3389.cc: New test.
* testsuite/24_iterators/move_iterator/lwg3390.cc: New test.

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/stl_iterator.h
libstdc++-v3/testsuite/24_iterators/counted_iterator/lwg3389.cc [new file with mode: 0644]
libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3390.cc [new file with mode: 0644]

index 922c715c8385faeef101d8feb1b5c39f17d057b8..cc4cfb7da0fbdf21cd338923ea3d5a429d575055 100644 (file)
@@ -1,3 +1,13 @@
+2020-02-12  Patrick Palka  <ppalka@redhat.com>
+
+       LWG 3389 and LWG 3390
+       * include/bits/stl_iterator.h (move_move_iterator): Use std::move when
+       constructing the move_iterator with __i.
+       (counted_iterator::counted_iterator): Use std::move when initializing
+       M_current with __i.
+       * testsuite/24_iterators/counted_iterator/lwg3389.cc: New test.
+       * testsuite/24_iterators/move_iterator/lwg3390.cc: New test.
+
 2020-02-12  Sandra Loosemore  <sandra@codesourcery.com>
 
        PR libstdc++/79193
index 4e70672924b6a808f6bbae3d28a4f0f799f8b6a4..fc9d442b47567c4f31b6065ace381f5771c80771 100644 (file)
@@ -1375,7 +1375,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Iterator>
     inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator>
     make_move_iterator(_Iterator __i)
-    { return move_iterator<_Iterator>(__i); }
+    { return move_iterator<_Iterator>(std::move(__i)); }
 
   template<typename _Iterator, typename _ReturnType
     = typename conditional<__move_if_noexcept_cond
@@ -1782,7 +1782,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       constexpr
       counted_iterator(_It __i, iter_difference_t<_It> __n)
-      : _M_current(__i), _M_length(__n)
+      : _M_current(std::move(__i)), _M_length(__n)
       { __glibcxx_assert(__n >= 0); }
 
       template<typename _It2>
diff --git a/libstdc++-v3/testsuite/24_iterators/counted_iterator/lwg3389.cc b/libstdc++-v3/testsuite/24_iterators/counted_iterator/lwg3389.cc
new file mode 100644 (file)
index 0000000..cf74fd4
--- /dev/null
@@ -0,0 +1,66 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <iterator>
+
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_range;
+using __gnu_test::input_iterator_wrapper;
+
+template<typename T>
+struct move_only_wrapper : input_iterator_wrapper<T>
+{
+  using input_iterator_wrapper<T>::input_iterator_wrapper;
+
+  move_only_wrapper()
+    : input_iterator_wrapper<T>(nullptr, nullptr)
+  { }
+
+  move_only_wrapper(const move_only_wrapper&) = delete;
+  move_only_wrapper&
+  operator=(const move_only_wrapper&) = delete;
+
+  move_only_wrapper(move_only_wrapper&&) = default;
+  move_only_wrapper&
+  operator=(move_only_wrapper&&) = default;
+
+  using input_iterator_wrapper<T>::operator++;
+
+  move_only_wrapper&
+  operator++()
+  {
+    input_iterator_wrapper<T>::operator++();
+    return *this;
+  }
+};
+
+static_assert(std::input_iterator<move_only_wrapper<int>>);
+static_assert(!std::forward_iterator<move_only_wrapper<int>>);
+static_assert(!std::copyable<move_only_wrapper<int>>);
+
+// LWG 3389
+void
+test01()
+{
+  int x[] = {1,2,3,4};
+  test_range<int, move_only_wrapper> rx(x);
+  auto it = std::counted_iterator(rx.begin(), 2);
+}
diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3390.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3390.cc
new file mode 100644 (file)
index 0000000..1df7cac
--- /dev/null
@@ -0,0 +1,66 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <iterator>
+
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_range;
+using __gnu_test::input_iterator_wrapper;
+
+template<typename T>
+struct move_only_wrapper : input_iterator_wrapper<T>
+{
+  using input_iterator_wrapper<T>::input_iterator_wrapper;
+
+  move_only_wrapper()
+    : input_iterator_wrapper<T>(nullptr, nullptr)
+  { }
+
+  move_only_wrapper(const move_only_wrapper&) = delete;
+  move_only_wrapper&
+  operator=(const move_only_wrapper&) = delete;
+
+  move_only_wrapper(move_only_wrapper&&) = default;
+  move_only_wrapper&
+  operator=(move_only_wrapper&&) = default;
+
+  using input_iterator_wrapper<T>::operator++;
+
+  move_only_wrapper&
+  operator++()
+  {
+    input_iterator_wrapper<T>::operator++();
+    return *this;
+  }
+};
+
+static_assert(std::input_iterator<move_only_wrapper<int>>);
+static_assert(!std::forward_iterator<move_only_wrapper<int>>);
+static_assert(!std::copyable<move_only_wrapper<int>>);
+
+// LWG 3390
+void
+test01()
+{
+  int x[] = {1,2,3,4};
+  test_range<int, move_only_wrapper> rx(x);
+  auto it = std::make_move_iterator(rx.begin());
+}