From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Add constexpr to std::counted_iterator post-increment (LWG 3643)
Date: Thu, 26 May 2022 17:24:03 +0100 [thread overview]
Message-ID: <20220526162403.1295781-1-jwakely@redhat.com> (raw)
Tested powerpc64le-linux, pushed to trunk.
This can be backported to 11 and 12 too.
-- >8 --
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.
---
libstdc++-v3/include/bits/stl_iterator.h | 3 +--
.../24_iterators/counted_iterator/lwg3643.cc | 27 +++++++++++++++++++
2 files changed, 28 insertions(+), 2 deletions(-)
create mode 100644 libstdc++-v3/testsuite/24_iterators/counted_iterator/lwg3643.cc
diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h
index 6a9fd1ba48e..12a89ab229f 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -2341,7 +2341,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return *this;
}
- decltype(auto)
+ constexpr decltype(auto)
operator++(int)
{
__glibcxx_assert(_M_length > 0);
@@ -2353,7 +2353,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 <iterator>
+
+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<InputIterator> );
+static_assert( !std::forward_iterator<InputIterator> );
+
+constexpr bool
+test_lwg3643()
+{
+ std::counted_iterator<InputIterator> iter({}, 1);
+ iter++;
+ return iter == std::default_sentinel;
+}
+
+static_assert( test_lwg3643() );
--
2.34.3
reply other threads:[~2022-05-26 16:24 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=20220526162403.1295781-1-jwakely@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).