From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1059) id 69028395200D; Thu, 11 Jun 2020 13:01:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 69028395200D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1591880494; bh=4BhLvelqF6Tw1SxcRFWVcj07jg6jHHjP9bxOd2ejeSM=; h=From:To:Subject:Date:From; b=sOSvxT/Nd+i91hgZxa9xd/Y10AQIda8T3oboGSnfLOlXNmVTzLrtVpnJ9lBGEI3PM UneDnaBjNOipUpXycPaZwhu6+zZGpXHbgzD9Z03FbGW+Tes0uXHKH0b7ki2ogWRxAP bX1uUNbuUcCADqBkZ5TjeI9K3EQJpMiFTrBKP2vU= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Nathan Sidwell To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc/devel/c++-modules] libstdc++: Fix __gnu_test::input_iterator_wrapper::operator++(int) X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/devel/c++-modules X-Git-Oldrev: 1746d5f3e67703a5b6a3a4fd8ca625672c321313 X-Git-Newrev: 118158b646d402b0fb5d760e4827611b731fe6f3 Message-Id: <20200611130134.69028395200D@sourceware.org> Date: Thu, 11 Jun 2020 13:01:34 +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, 11 Jun 2020 13:01:34 -0000 https://gcc.gnu.org/g:118158b646d402b0fb5d760e4827611b731fe6f3 commit 118158b646d402b0fb5d760e4827611b731fe6f3 Author: Jonathan Wakely Date: Mon Jun 1 18:30:47 2020 +0100 libstdc++: Fix __gnu_test::input_iterator_wrapper::operator++(int) I noticed recently that our input_iterator_wrapper utility for writing tests has the following post-increment operator: void operator++(int) { ++*this; } That fails to meet the Cpp17InputIterator requirement that *r++ is valid. This change makes it return a non-void proxy type that can be deferenced to produce another proxy, which is convertible to the value_type. The second proxy converts to const T& to ensure it can't be written to. * testsuite/util/testsuite_iterators.h: (input_iterator_wrapper::operator++(int)): Return proxy object. Diff: --- libstdc++-v3/testsuite/util/testsuite_iterators.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h index 5be47f47915..71b672c85fa 100644 --- a/libstdc++-v3/testsuite/util/testsuite_iterators.h +++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h @@ -208,6 +208,17 @@ namespace __gnu_test : public std::iterator::type, std::ptrdiff_t, T*, T&> { + struct post_inc_proxy + { + struct deref_proxy + { + T* ptr; + operator const T&() const { return *ptr; } + } p; + + deref_proxy operator*() const { return p; } + }; + protected: input_iterator_wrapper() : ptr(0), SharedInfo(0) { } @@ -266,10 +277,12 @@ namespace __gnu_test return *this; } - void + post_inc_proxy operator++(int) { + post_inc_proxy tmp = { { ptr } }; ++*this; + return tmp; } #if __cplusplus >= 201103L