Debian Codegraph @

libstdc++-v3/testsuite/24_iterators/common_iterator/100823.cc

raw
1 // { dg-options "-D_GLIBCXX_ASSERTIONS" }
2 // { dg-do run { target c++20 } }
3 #include <iterator>
4 #include <testsuite_iterators.h>
5 #include <testsuite_hooks.h>
6
7 void
8 test_triviality()
9 {
10 using I = std::common_iterator<int*, const int*>;
11
12 // Cannot be trivial, because it has to initialize members.
13 static_assert( ! std::is_trivially_default_constructible_v<I> );
14
15 static_assert( std::is_trivially_destructible_v<I> );
16 static_assert( std::is_trivially_copy_constructible_v<I> );
17 static_assert( std::is_trivially_copy_assignable_v<I> );
18 static_assert( std::is_trivially_move_constructible_v<I> );
19 static_assert( std::is_trivially_move_assignable_v<I> );
20 }
21
22 void
23 test_valueless_assignment()
24 {
25 int x[1] { };
26 __gnu_test::test_forward_range<int> r(x);
27 using Iter = decltype(r.begin());
28 using Sent = decltype(r.end());
29
30 std::common_iterator<Iter, Sent> i;
31 const std::common_iterator<Iter, Sent> j(r.begin());
32 try
33 {
34 struct Bomb
35 {
36 bool operator==(Iter) const { return true; }
37 operator Sent() const { throw 1; }
38 };
39 std::common_iterator<Iter, Bomb> b{Bomb{}};
40 i = b; // Throws, leaving i valueless-by-exception.
41 VERIFY(false);
42 }
43 catch (int)
44 {
45 std::common_iterator<Iter, Sent> k(i);
46
47 // PR libstdc++/100823
48 k = i; // Valid even though both operands are valueless.
49
50 i = j; // No longer valueless.
51 }
52 VERIFY( i == j );
53 }
54
55 int main()
56 {
57 test_valueless_assignment();
58 }