public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/autopar_devel] libstdc++: Fix __gnu_test::input_iterator_wrapper::operator++(int)
@ 2020-08-22 21:47 Giuliano Belinassi
0 siblings, 0 replies; only message in thread
From: Giuliano Belinassi @ 2020-08-22 21:47 UTC (permalink / raw)
To: gcc-cvs, libstdc++-cvs
https://gcc.gnu.org/g:ed91d55958cbb8292565ffd2af10e9cfb8c5870d
commit ed91d55958cbb8292565ffd2af10e9cfb8c5870d
Author: Jonathan Wakely <jwakely@redhat.com>
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<std::input_iterator_tag, typename remove_cv<T>::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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-08-22 21:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-22 21:47 [gcc/devel/autopar_devel] libstdc++: Fix __gnu_test::input_iterator_wrapper::operator++(int) Giuliano Belinassi
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).