From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 804AB384B823; Thu, 7 Jul 2022 23:33:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 804AB384B823 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-10136] libstdc++: Add constexpr to std::counted_iterator post-increment (LWG 3643) X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 03af8492bee6243a9d10e78fea1a3e423bd5f9cd X-Git-Newrev: debbc74f170c9e3ccbb7eaea13fb483a619a6dbf Message-Id: <20220707233346.804AB384B823@sourceware.org> Date: Thu, 7 Jul 2022 23:33:46 +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, 07 Jul 2022 23:33:46 -0000 https://gcc.gnu.org/g:debbc74f170c9e3ccbb7eaea13fb483a619a6dbf commit r11-10136-gdebbc74f170c9e3ccbb7eaea13fb483a619a6dbf Author: Jonathan Wakely Date: Thu May 26 12:41:03 2022 +0100 libstdc++: Add constexpr to std::counted_iterator post-increment (LWG 3643) libstdc++-v3/ChangeLog: * include/bits/stl_iterator.h (counted_iterator::operator++(int)): Add 'constexpr' as per LWG 3643. * testsuite/24_iterators/counted_iterator/lwg3643.cc: New test. (cherry picked from commit 47b20d027ade5bfbd932724d0ea2aedee7421243) Diff: --- libstdc++-v3/include/bits/stl_iterator.h | 3 +-- .../24_iterators/counted_iterator/lwg3643.cc | 27 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 4247bb116c3..38a828e633e 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -2223,7 +2223,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } - decltype(auto) + constexpr decltype(auto) operator++(int) { __glibcxx_assert(_M_length > 0); @@ -2235,7 +2235,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ++_M_length; __throw_exception_again; } - } constexpr counted_iterator diff --git a/libstdc++-v3/testsuite/24_iterators/counted_iterator/lwg3643.cc b/libstdc++-v3/testsuite/24_iterators/counted_iterator/lwg3643.cc new file mode 100644 index 00000000000..e6f12b46c12 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/counted_iterator/lwg3643.cc @@ -0,0 +1,27 @@ +// { dg-options "-std=gnu++20" } +// { dg-do compile { target c++20 } } + +#include + +struct InputIterator +{ + using difference_type = int; + using value_type = int; + + constexpr int operator*() const noexcept { return 0; } + InputIterator& operator++() { return *this; } + constexpr void operator++(int) { } +}; + +static_assert( std::input_iterator ); +static_assert( !std::forward_iterator ); + +constexpr bool +test_lwg3643() +{ + std::counted_iterator iter({}, 1); + iter++; + return iter == std::default_sentinel; +} + +static_assert( test_lwg3643() );