public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-9905] libstdc++: Implement LWG 3391 changes to move/counted_iterator::base() Date: Thu, 10 Jun 2021 19:08:06 +0000 (GMT) [thread overview] Message-ID: <20210610190806.D6ADA39960FF@sourceware.org> (raw) https://gcc.gnu.org/g:6c0ce0194d3384cd5c6e8a83a39cf3e33a36caeb commit r10-9905-g6c0ce0194d3384cd5c6e8a83a39cf3e33a36caeb Author: Patrick Palka <ppalka@redhat.com> Date: Thu May 6 09:11:42 2021 -0400 libstdc++: Implement LWG 3391 changes to move/counted_iterator::base() libstdc++-v3/ChangeLog: * include/bits/stl_iterator.h (move_iterator::base): Make the const& overload unconstrained and return a const reference 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(). (cherry picked from commit 08f3287eefea1d7c244db795d018870e8148d1c8) Diff: --- 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(-) diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 3a3df0b7961..244f72d64b3 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -1362,11 +1362,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 @@ -2094,10 +2091,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 eaf307ddf60..7f4dda11e11 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>;
reply other threads:[~2021-06-10 19:08 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210610190806.D6ADA39960FF@sourceware.org \ --to=ppalka@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).