public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Support N3644 "Null Forward Iterators" for testsuite iterators
Date: Thu, 27 Feb 2020 13:03:00 -0000	[thread overview]
Message-ID: <20200227130309.GA2514880@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 320 bytes --]

Comparing value-initialized forward_iterator_wrapper<T> objects fails an
assertion, but should be valid in C++14 and later.

	* testsuite/util/testsuite_iterators.h (forward_iterator_wrapper): Add
	equality comparisons that support value-initialized iterators.

Tested powerpc64le-linux, committed to master.



[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1535 bytes --]

commit e94f2542305ccb5c4a3c4e5e8212713747623417
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Feb 27 13:01:14 2020 +0000

    libstdc++: Support N3644 "Null Forward Iterators" for testsuite iterators
    
    Comparing value-initialized forward_iterator_wrapper<T> objects fails an
    assertion, but should be valid in C++14 and later.
    
            * testsuite/util/testsuite_iterators.h (forward_iterator_wrapper): Add
            equality comparisons that support value-initialized iterators.

diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h
index 7b7093919b7..417dff23c50 100644
--- a/libstdc++-v3/testsuite/util/testsuite_iterators.h
+++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h
@@ -337,6 +337,26 @@ namespace __gnu_test
       ++*this;
       return tmp;
     }
+
+#if __cplusplus >= 201402L
+    bool
+    operator==(const forward_iterator_wrapper& it) const noexcept
+    {
+      // Since C++14 value-initialized forward iterators are comparable.
+      if (this->SharedInfo == nullptr || it.SharedInfo == nullptr)
+	return this->SharedInfo == it.SharedInfo && this->ptr == it.ptr;
+
+      const input_iterator_wrapper<T>& base_this = *this;
+      const input_iterator_wrapper<T>& base_that = it;
+      return base_this == base_that;
+    }
+
+    bool
+    operator!=(const forward_iterator_wrapper& it) const noexcept
+    {
+      return !(*this == it);
+    }
+#endif
   };
 
   /**

                 reply	other threads:[~2020-02-27 13:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200227130309.GA2514880@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /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).