public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Patrick Palka <ppalka@redhat.com>
Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: [PATCH 1/3] libstdc++: Apply the move_iterator changes described in P1207R4
Date: Tue, 04 Feb 2020 10:41:00 -0000	[thread overview]
Message-ID: <20200204104113.GL9441@redhat.com> (raw)
In-Reply-To: <20200204020724.217468-1-ppalka@redhat.com>

On 03/02/20 21:07 -0500, Patrick Palka wrote:
>These changes are needed for some of the tests in the constrained algorithm
>patch, because they use move_iterator with an uncopyable output_iterator.  The
>other changes described in the paper are already applied, it seems.
>
>libstdc++-v3/ChangeLog:
>
>	* include/bits/stl_iterator.h (move_iterator::move_iterator): Move the
>	iterator when initializing _M_current.
>	(move_iterator::base): Split into two overloads differing in
>	ref-qualifiers as in P1207R4.
>---
> libstdc++-v3/include/bits/stl_iterator.h | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
>diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h
>index 784d200d22f..1a288a5c785 100644
>--- a/libstdc++-v3/include/bits/stl_iterator.h
>+++ b/libstdc++-v3/include/bits/stl_iterator.h
>@@ -1166,7 +1166,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>
>       explicit _GLIBCXX17_CONSTEXPR
>       move_iterator(iterator_type __i)
>-      : _M_current(__i) { }
>+      : _M_current(std::move(__i)) { }
>
>       template<typename _Iter>
> 	_GLIBCXX17_CONSTEXPR
>@@ -1174,9 +1174,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> 	: _M_current(__i.base()) { }
>
>       _GLIBCXX17_CONSTEXPR iterator_type
>-      base() const
>+      base() const &
>+#if __cplusplus > 201703L && __cpp_lib_concepts
>+	requires copy_constructible<iterator_type>
>+#endif
>       { return _M_current; }
>
>+      _GLIBCXX17_CONSTEXPR iterator_type
>+      base() &&
>+      { return std::move(_M_current); }
>+

I think this change has to be restricted to C++20 and later, otherwise
a move_iterator in C++17 can change state so that its _M_current
becomes moved-from, which should not be possible before C++20.

So something like:

#if __cplusplus <= 201703L
       _GLIBCXX17_CONSTEXPR iterator_type
       base() const
       { return _M_current; }
#else
       constexpr iterator_type
       base() const &
#if __cpp_lib_concepts
	requires copy_constructible<iterator_type>
#endif
       { return _M_current; }

       constexpr iterator_type
       base() &&
       { return std::move(_M_current); }
#endif

  parent reply	other threads:[~2020-02-04 10:41 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-04  2:07 Patrick Palka
2020-02-04  2:08 ` [PATCH 3/3] libstdc++: Implement C++20 range adaptors Patrick Palka
2020-02-06 17:25   ` Jonathan Wakely
2020-02-06 23:53     ` Patrick Palka
2020-02-07 11:48       ` Jonathan Wakely
2020-02-07 14:28         ` Patrick Palka
2020-02-17 22:07   ` Stephan Bergmann
2020-02-18  1:20     ` Patrick Palka
2020-02-18  7:31       ` Stephan Bergmann
2020-02-18 11:56       ` Jonathan Wakely
2020-02-18 20:11         ` Stephan Bergmann
2020-02-18 23:41           ` Jonathan Wakely
2020-02-18 10:14     ` Jonathan Wakely
2020-02-04  2:09 ` [PATCH 2/3] libstdc++: Implement C++20 constrained algorithms Patrick Palka
2020-02-05 18:39   ` François Dumont
2020-02-05 19:05     ` Patrick Palka
2020-02-05 19:25     ` Patrick Palka
2020-02-06 10:39       ` Jonathan Wakely
2020-02-06 12:36     ` Jonathan Wakely
2020-02-06 16:25   ` Jonathan Wakely
2020-02-07  1:13     ` Patrick Palka
2020-02-07 13:51   ` Jonathan Wakely
2020-02-13 18:07   ` François Dumont
2020-02-13 19:00     ` Jonathan Wakely
2020-02-14  6:00       ` François Dumont
2020-02-04 10:41 ` Jonathan Wakely [this message]
2020-02-04 21:23   ` [PATCH 1/3] libstdc++: Apply the move_iterator changes described in P1207R4 Patrick Palka
2020-02-04 21:49     ` Jonathan Wakely

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=20200204104113.GL9441@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    --cc=ppalka@redhat.com \
    /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: link
Be 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).