summaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-05-26 12:41:03 +0100
committerJonathan Wakely <jwakely@redhat.com>2022-05-27 18:32:52 +0100
commit7be1dd924db806175ddb3c4eb34390d4981cbf11 (patch)
tree49e03b2d77121248f7a2753ae0f73750fc162e8c /libstdc++-v3
parent5647e401bb8656d1d9897c7a536bf00ff50fd20b (diff)
libstdc++: Add constexpr to std::counted_iterator post-increment (LWG 3643)
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. (cherry picked from commit 47b20d027ade5bfbd932724d0ea2aedee7421243)
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/include/bits/stl_iterator.h3
-rw-r--r--libstdc++-v3/testsuite/24_iterators/counted_iterator/lwg3643.cc27
2 files changed, 28 insertions, 2 deletions
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() );