]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/forward_list/operations/remove_freed.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / forward_list / operations / remove_freed.cc
1 // { dg-do run { target c++11 } }
2
3 // 2010-08-11 Paolo Carlini <paolo.carlini@oracle.com>
4 //
5 // Copyright (C) 2010-2020 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
21
22 #include <forward_list>
23 #include <testsuite_hooks.h>
24
25 // 23.3.3.5 forward_list operations [forwardlist.ops]
26
27 // Used to cause many Valgrind errors: LWG 526-type situation.
28 void test01()
29 {
30 std::forward_list<int> fl1;
31
32 fl1.push_front(1);
33 fl1.push_front(2);
34 fl1.push_front(3);
35 fl1.push_front(4);
36 fl1.push_front(1);
37
38 fl1.remove(*fl1.begin());
39
40 VERIFY( std::distance(fl1.begin(), fl1.end()) == 3 );
41
42 auto it1 = fl1.begin();
43
44 VERIFY( *it1 == 4 );
45 ++it1;
46 VERIFY( *it1 == 3 );
47 ++it1;
48 VERIFY( *it1 == 2 );
49
50 std::forward_list<int> fl2;
51
52 fl2.push_front(3);
53 fl2.push_front(3);
54 fl2.push_front(3);
55 fl2.push_front(3);
56 fl2.push_front(3);
57
58 auto it2 = fl2.begin();
59 ++it2;
60 ++it2;
61
62 fl2.remove(*it2);
63
64 VERIFY( std::distance(fl2.begin(), fl2.end()) == 0 );
65
66 std::forward_list<int> fl3;
67
68 fl3.push_front(1);
69 fl3.push_front(2);
70 fl3.push_front(3);
71 fl3.push_front(3);
72 fl3.push_front(3);
73
74 auto it3 = fl3.begin();
75 ++it3;
76 ++it3;
77
78 fl3.remove(*it3);
79
80 VERIFY( std::distance(fl3.begin(), fl3.end()) == 2 );
81
82 it3 = fl3.begin();
83 VERIFY( *it3 == 2 );
84 ++it3;
85 VERIFY( *it3 == 1 );
86 }
87
88 int main()
89 {
90 test01();
91 return 0;
92 }