summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/24_iterators/common_iterator/100823.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/testsuite/24_iterators/common_iterator/100823.cc')
-rw-r--r--libstdc++-v3/testsuite/24_iterators/common_iterator/100823.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/24_iterators/common_iterator/100823.cc b/libstdc++-v3/testsuite/24_iterators/common_iterator/100823.cc
new file mode 100644
index 00000000000..4f2b23de8cc
--- /dev/null
+++ b/libstdc++-v3/testsuite/24_iterators/common_iterator/100823.cc
@@ -0,0 +1,43 @@
+// { dg-options "-std=gnu++20 -D_GLIBCXX_ASSERTIONS" }
+// { dg-do run { target c++20 } }
+#include <iterator>
+#include <testsuite_iterators.h>
+#include <testsuite_hooks.h>
+
+void
+test_valueless_assignment()
+{
+ int x[1] { };
+ __gnu_test::test_forward_range<int> r(x);
+ using Iter = decltype(r.begin());
+ using Sent = decltype(r.end());
+
+ std::common_iterator<Iter, Sent> i;
+ const std::common_iterator<Iter, Sent> j(r.begin());
+ try
+ {
+ struct Bomb
+ {
+ bool operator==(Iter) const { return true; }
+ operator Sent() const { throw 1; }
+ };
+ std::common_iterator<Iter, Bomb> b{Bomb{}};
+ i = b; // Throws, leaving i valueless-by-exception.
+ VERIFY(false);
+ }
+ catch (int)
+ {
+ std::common_iterator<Iter, Sent> k(i);
+
+ // PR libstdc++/100823
+ k = i; // Valid even though both operands are valueless.
+
+ i = j; // No longer valueless.
+ }
+ VERIFY( i == j );
+}
+
+int main()
+{
+ test_valueless_assignment();
+}