From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id F24B7398D063; Thu, 10 Jun 2021 19:03:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F24B7398D063 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-8543] libstdc++: Implement LWG 3391 changes to move/counted_iterator::base() X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 3b93d61be5a5a93e95783b80c58b297e215badf1 X-Git-Newrev: 048eb89a1e76acb4a84a9a08cff2fd3c1109191e Message-Id: <20210610190318.F24B7398D063@sourceware.org> Date: Thu, 10 Jun 2021 19:03:18 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jun 2021 19:03:19 -0000 https://gcc.gnu.org/g:048eb89a1e76acb4a84a9a08cff2fd3c1109191e commit r11-8543-g048eb89a1e76acb4a84a9a08cff2fd3c1109191e Author: Patrick Palka 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 08c1edfba07..8768624b7d1 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -1412,11 +1412,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION base() const { return _M_current; } #else - constexpr iterator_type - base() const & -#if __cpp_lib_concepts - requires copy_constructible -#endif + constexpr const iterator_type& + base() const & noexcept { return _M_current; } constexpr iterator_type @@ -2144,10 +2141,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 +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// Verify LWG 3391 changes. + +#include +#include + +#include + +using __gnu_test::test_range; +using __gnu_test::input_iterator_wrapper_nocopy; + +void +test01() +{ + extern test_range 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 static_assert(std::input_iterator); template - concept has_member_base = requires (T t) { std::forward(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).base()); + }; using move_only_move_iterator = std::move_iterator;