* [PATCH 1/2] libstdc++: Implement LWG 3391 changes to move/counted_iterator::base
@ 2021-05-05 20:23 Patrick Palka
2021-05-05 20:23 ` [PATCH 2/2] libstdc++: Implement LWG 3533 changes to foo_view::iterator::base() Patrick Palka
2021-05-06 10:27 ` [PATCH 1/2] libstdc++: Implement LWG 3391 changes to move/counted_iterator::base Jonathan Wakely
0 siblings, 2 replies; 4+ messages in thread
From: Patrick Palka @ 2021-05-05 20:23 UTC (permalink / raw)
To: gcc-patches; +Cc: libstdc++, Patrick Palka
Tested on x86_64-pc-linux-gnu, does this look OK for trunk/10/11?
libstdc++-v3/ChangeLog:
* include/bits/stl_iterator.h (move_iterator::base): Make the
const& overload return a const reference and remove its
constraint as per LWG 3391. Make unconditionally noexcept.
(counted_iterator::base): Likewise.
* testsuite/24_iterators/move_iterator/lwg3391.cc: New test.
* testsuite/24_iterators/move_iterator/move_only.cc: Adjust
has_member_base concept to decay-copy the result of base().
---
libstdc++-v3/include/bits/stl_iterator.h | 13 ++-----
.../24_iterators/move_iterator/lwg3391.cc | 37 +++++++++++++++++++
.../24_iterators/move_iterator/move_only.cc | 8 +++-
3 files changed, 48 insertions(+), 10 deletions(-)
create mode 100644 libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3391.cc
diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h
index 049f83cff90..2409cd71f86 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -1409,11 +1409,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
base() const
{ return _M_current; }
#else
- constexpr iterator_type
- base() const &
-#if __cpp_lib_concepts
- requires copy_constructible<iterator_type>
-#endif
+ constexpr const iterator_type&
+ base() const & noexcept
{ return _M_current; }
constexpr iterator_type
@@ -2141,10 +2138,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return *this;
}
- constexpr _It
- base() const &
- noexcept(is_nothrow_copy_constructible_v<_It>)
- requires copy_constructible<_It>
+ constexpr const _It&
+ base() const & noexcept
{ return _M_current; }
constexpr _It
diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3391.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3391.cc
new file mode 100644
index 00000000000..18e015777cd
--- /dev/null
+++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3391.cc
@@ -0,0 +1,37 @@
+// Copyright (C) 2021 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 } }
+
+// Verify LWG 3391 changes.
+
+#include <iterator>
+#include <ranges>
+
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_range;
+using __gnu_test::input_iterator_wrapper_nocopy;
+
+void
+test01()
+{
+ extern test_range<int, input_iterator_wrapper_nocopy> rx;
+ auto v = rx | std::views::take(5);
+ std::ranges::begin(v) != std::ranges::end(v);
+}
diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/move_only.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/move_only.cc
index 639adfab0e2..5537dfbf3cd 100644
--- a/libstdc++-v3/testsuite/24_iterators/move_iterator/move_only.cc
+++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/move_only.cc
@@ -43,7 +43,13 @@ template<> struct std::iterator_traits<move_only_iterator>
static_assert(std::input_iterator<move_only_iterator>);
template<typename T>
- concept has_member_base = requires (T t) { std::forward<T>(t).base(); };
+ concept has_member_base = requires (T t) {
+ // LWG 3391 made the const& overload of move_iterator::base()
+ // unconstrained and return a const reference. So rather than checking
+ // whether base() is valid (which is now trivially true in an unevaluated
+ // context), the below now checks whether decay-copying base() is valid.
+ [](auto){}(std::forward<T>(t).base());
+ };
using move_only_move_iterator = std::move_iterator<move_only_iterator>;
--
2.31.1.442.g7e39198978
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] libstdc++: Implement LWG 3533 changes to foo_view::iterator::base()
2021-05-05 20:23 [PATCH 1/2] libstdc++: Implement LWG 3391 changes to move/counted_iterator::base Patrick Palka
@ 2021-05-05 20:23 ` Patrick Palka
2021-05-06 10:28 ` Jonathan Wakely
2021-05-06 10:27 ` [PATCH 1/2] libstdc++: Implement LWG 3391 changes to move/counted_iterator::base Jonathan Wakely
1 sibling, 1 reply; 4+ messages in thread
From: Patrick Palka @ 2021-05-05 20:23 UTC (permalink / raw)
To: gcc-patches; +Cc: libstdc++, Patrick Palka
Tested on x86_64-pc-linux-gnu, does this look OK for trunk/10/11?
libstdc++-v3/ChangeLog:
* include/std/ranges (filter_view::_Iterator::base): Make the
const& overload return a const reference and remove its
constraint as per LWG 3533. Make unconditionally noexcept.
(transform_view::_Iterator::base): Likewise.
(elements_view::_Iterator::base): Likewise.
---
libstdc++-v3/include/std/ranges | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 7075fa3ae6e..bc11505c167 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -1199,9 +1199,8 @@ namespace views::__adaptor
_M_parent(__parent)
{ }
- constexpr _Vp_iter
- base() const &
- requires copyable<_Vp_iter>
+ constexpr const _Vp_iter&
+ base() const & noexcept
{ return _M_current; }
constexpr _Vp_iter
@@ -1467,9 +1466,8 @@ namespace views::__adaptor
: _M_current(std::move(__i._M_current)), _M_parent(__i._M_parent)
{ }
- constexpr _Base_iter
- base() const &
- requires copyable<_Base_iter>
+ constexpr const _Base_iter&
+ base() const & noexcept
{ return _M_current; }
constexpr _Base_iter
@@ -3403,8 +3401,8 @@ namespace views::__adaptor
: _M_base(std::move(base))
{ }
- constexpr _Vp
- base() const& requires copy_constructible<_Vp>
+ constexpr const _Vp&
+ base() const & noexcept
{ return _M_base; }
constexpr _Vp
--
2.31.1.442.g7e39198978
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] libstdc++: Implement LWG 3391 changes to move/counted_iterator::base
2021-05-05 20:23 [PATCH 1/2] libstdc++: Implement LWG 3391 changes to move/counted_iterator::base Patrick Palka
2021-05-05 20:23 ` [PATCH 2/2] libstdc++: Implement LWG 3533 changes to foo_view::iterator::base() Patrick Palka
@ 2021-05-06 10:27 ` Jonathan Wakely
1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2021-05-06 10:27 UTC (permalink / raw)
To: Patrick Palka; +Cc: gcc-patches, libstdc++
On 05/05/21 16:23 -0400, Patrick Palka via Libstdc++ wrote:
>Tested on x86_64-pc-linux-gnu, does this look OK for trunk/10/11?
Yes, thanks.
>libstdc++-v3/ChangeLog:
>
> * include/bits/stl_iterator.h (move_iterator::base): Make the
> const& overload return a const reference and remove its
> constraint as per LWG 3391. Make unconditionally noexcept.
> (counted_iterator::base): Likewise.
> * testsuite/24_iterators/move_iterator/lwg3391.cc: New test.
> * testsuite/24_iterators/move_iterator/move_only.cc: Adjust
> has_member_base concept to decay-copy the result of base().
>---
> libstdc++-v3/include/bits/stl_iterator.h | 13 ++-----
> .../24_iterators/move_iterator/lwg3391.cc | 37 +++++++++++++++++++
> .../24_iterators/move_iterator/move_only.cc | 8 +++-
> 3 files changed, 48 insertions(+), 10 deletions(-)
> create mode 100644 libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3391.cc
>
>diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h
>index 049f83cff90..2409cd71f86 100644
>--- a/libstdc++-v3/include/bits/stl_iterator.h
>+++ b/libstdc++-v3/include/bits/stl_iterator.h
>@@ -1409,11 +1409,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> base() const
> { return _M_current; }
> #else
>- constexpr iterator_type
>- base() const &
>-#if __cpp_lib_concepts
>- requires copy_constructible<iterator_type>
>-#endif
>+ constexpr const iterator_type&
>+ base() const & noexcept
> { return _M_current; }
>
> constexpr iterator_type
>@@ -2141,10 +2138,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> return *this;
> }
>
>- constexpr _It
>- base() const &
>- noexcept(is_nothrow_copy_constructible_v<_It>)
>- requires copy_constructible<_It>
>+ constexpr const _It&
>+ base() const & noexcept
> { return _M_current; }
>
> constexpr _It
>diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3391.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3391.cc
>new file mode 100644
>index 00000000000..18e015777cd
>--- /dev/null
>+++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3391.cc
>@@ -0,0 +1,37 @@
>+// Copyright (C) 2021 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 } }
>+
>+// Verify LWG 3391 changes.
>+
>+#include <iterator>
>+#include <ranges>
>+
>+#include <testsuite_iterators.h>
>+
>+using __gnu_test::test_range;
>+using __gnu_test::input_iterator_wrapper_nocopy;
>+
>+void
>+test01()
>+{
>+ extern test_range<int, input_iterator_wrapper_nocopy> rx;
>+ auto v = rx | std::views::take(5);
>+ std::ranges::begin(v) != std::ranges::end(v);
>+}
>diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/move_only.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/move_only.cc
>index 639adfab0e2..5537dfbf3cd 100644
>--- a/libstdc++-v3/testsuite/24_iterators/move_iterator/move_only.cc
>+++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/move_only.cc
>@@ -43,7 +43,13 @@ template<> struct std::iterator_traits<move_only_iterator>
> static_assert(std::input_iterator<move_only_iterator>);
>
> template<typename T>
>- concept has_member_base = requires (T t) { std::forward<T>(t).base(); };
>+ concept has_member_base = requires (T t) {
>+ // LWG 3391 made the const& overload of move_iterator::base()
>+ // unconstrained and return a const reference. So rather than checking
>+ // whether base() is valid (which is now trivially true in an unevaluated
>+ // context), the below now checks whether decay-copying base() is valid.
>+ [](auto){}(std::forward<T>(t).base());
>+ };
>
> using move_only_move_iterator = std::move_iterator<move_only_iterator>;
>
>--
>2.31.1.442.g7e39198978
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] libstdc++: Implement LWG 3533 changes to foo_view::iterator::base()
2021-05-05 20:23 ` [PATCH 2/2] libstdc++: Implement LWG 3533 changes to foo_view::iterator::base() Patrick Palka
@ 2021-05-06 10:28 ` Jonathan Wakely
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2021-05-06 10:28 UTC (permalink / raw)
To: Patrick Palka; +Cc: gcc-patches, libstdc++
On 05/05/21 16:23 -0400, Patrick Palka via Libstdc++ wrote:
>Tested on x86_64-pc-linux-gnu, does this look OK for trunk/10/11?
Yes, thanks.
>libstdc++-v3/ChangeLog:
>
> * include/std/ranges (filter_view::_Iterator::base): Make the
> const& overload return a const reference and remove its
> constraint as per LWG 3533. Make unconditionally noexcept.
> (transform_view::_Iterator::base): Likewise.
> (elements_view::_Iterator::base): Likewise.
>---
> libstdc++-v3/include/std/ranges | 14 ++++++--------
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
>diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
>index 7075fa3ae6e..bc11505c167 100644
>--- a/libstdc++-v3/include/std/ranges
>+++ b/libstdc++-v3/include/std/ranges
>@@ -1199,9 +1199,8 @@ namespace views::__adaptor
> _M_parent(__parent)
> { }
>
>- constexpr _Vp_iter
>- base() const &
>- requires copyable<_Vp_iter>
>+ constexpr const _Vp_iter&
>+ base() const & noexcept
> { return _M_current; }
>
> constexpr _Vp_iter
>@@ -1467,9 +1466,8 @@ namespace views::__adaptor
> : _M_current(std::move(__i._M_current)), _M_parent(__i._M_parent)
> { }
>
>- constexpr _Base_iter
>- base() const &
>- requires copyable<_Base_iter>
>+ constexpr const _Base_iter&
>+ base() const & noexcept
> { return _M_current; }
>
> constexpr _Base_iter
>@@ -3403,8 +3401,8 @@ namespace views::__adaptor
> : _M_base(std::move(base))
> { }
>
>- constexpr _Vp
>- base() const& requires copy_constructible<_Vp>
>+ constexpr const _Vp&
>+ base() const & noexcept
> { return _M_base; }
>
> constexpr _Vp
>--
>2.31.1.442.g7e39198978
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-05-06 10:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-05 20:23 [PATCH 1/2] libstdc++: Implement LWG 3391 changes to move/counted_iterator::base Patrick Palka
2021-05-05 20:23 ` [PATCH 2/2] libstdc++: Implement LWG 3533 changes to foo_view::iterator::base() Patrick Palka
2021-05-06 10:28 ` Jonathan Wakely
2021-05-06 10:27 ` [PATCH 1/2] libstdc++: Implement LWG 3391 changes to move/counted_iterator::base Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).