Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / input.output / filesystems / class.rec.dir.itr / rec.dir.itr.members / move_assign.pass.cpp
blob0770f797720135dc04ccd597c9a63db1d2bf7ed2
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03
10 // UNSUPPORTED: no-filesystem
11 // UNSUPPORTED: availability-filesystem-missing
13 // <filesystem>
15 // class recursive_directory_iterator
17 // recursive_directory_iterator& operator=(recursive_directory_iterator const&);
19 #include "filesystem_include.h"
20 #include <type_traits>
21 #include <set>
22 #include <cassert>
24 #include "test_macros.h"
25 #include "filesystem_test_helper.h"
27 // The filesystem specification explicitly allows for self-move on
28 // the directory iterators. Turn off this warning so we can test it.
29 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wself-move")
31 using namespace fs;
33 recursive_directory_iterator createInterestingIterator(const static_test_env &static_env)
34 // Create an "interesting" iterator where all fields are
35 // in a non-default state. The returned 'it' is in a
36 // state such that:
37 // it.options() == directory_options::skip_permission_denied
38 // it.depth() == 1
39 // it.recursion_pending() == true
41 const path testDir = static_env.Dir;
42 const recursive_directory_iterator endIt;
43 recursive_directory_iterator it(testDir,
44 directory_options::skip_permission_denied);
45 assert(it != endIt);
46 while (it.depth() != 1) {
47 ++it;
48 assert(it != endIt);
50 assert(it.depth() == 1);
51 it.disable_recursion_pending();
52 return it;
55 recursive_directory_iterator createDifferentInterestingIterator(const static_test_env &static_env)
56 // Create an "interesting" iterator where all fields are
57 // in a non-default state. The returned 'it' is in a
58 // state such that:
59 // it.options() == directory_options::follow_directory_symlink
60 // it.depth() == 2
61 // it.recursion_pending() == false
63 const path testDir = static_env.Dir;
64 const recursive_directory_iterator endIt;
65 recursive_directory_iterator it(testDir,
66 directory_options::follow_directory_symlink);
67 assert(it != endIt);
68 while (it.depth() != 2) {
69 ++it;
70 assert(it != endIt);
72 assert(it.depth() == 2);
73 return it;
77 static void test_assignment_signature()
79 using D = recursive_directory_iterator;
80 static_assert(std::is_nothrow_move_assignable<D>::value, "");
84 static void test_move_to_end_iterator()
86 static_test_env static_env;
87 const recursive_directory_iterator endIt;
89 recursive_directory_iterator from = createInterestingIterator(static_env);
90 const recursive_directory_iterator from_copy(from);
91 const path entry = *from;
93 recursive_directory_iterator to;
94 to = std::move(from);
95 assert(to != endIt);
96 assert(*to == entry);
97 assert(to.options() == from_copy.options());
98 assert(to.depth() == from_copy.depth());
99 assert(to.recursion_pending() == from_copy.recursion_pending());
100 assert(from == endIt || from == to);
104 static void test_move_from_end_iterator()
106 static_test_env static_env;
107 recursive_directory_iterator from;
108 recursive_directory_iterator to = createInterestingIterator(static_env);
110 to = std::move(from);
111 assert(to == from);
112 assert(to == recursive_directory_iterator{});
115 static void test_move_valid_iterator()
117 static_test_env static_env;
118 const recursive_directory_iterator endIt;
120 recursive_directory_iterator it = createInterestingIterator(static_env);
121 const recursive_directory_iterator it_copy(it);
122 const path entry = *it;
124 recursive_directory_iterator it2 = createDifferentInterestingIterator(static_env);
125 const recursive_directory_iterator it2_copy(it2);
126 assert(it2 != it);
127 assert(it2.options() != it.options());
128 assert(it2.depth() != it.depth());
129 assert(it2.recursion_pending() != it.recursion_pending());
130 assert(*it2 != entry);
132 it2 = std::move(it);
133 assert(it2 != it2_copy && it2 != endIt);
134 assert(it2.options() == it_copy.options());
135 assert(it2.depth() == it_copy.depth());
136 assert(it2.recursion_pending() == it_copy.recursion_pending());
137 assert(*it2 == entry);
138 assert(it == endIt || it == it2);
141 static void test_returns_reference_to_self()
143 recursive_directory_iterator it;
144 recursive_directory_iterator it2;
145 recursive_directory_iterator& ref = (it2 = std::move(it));
146 assert(&ref == &it2);
149 static void test_self_move()
151 static_test_env static_env;
152 // Create two non-equal iterators that have exactly the same state.
153 recursive_directory_iterator it = createInterestingIterator(static_env);
154 recursive_directory_iterator it2 = createInterestingIterator(static_env);
155 assert(it != it2);
156 assert(it2.options() == it.options());
157 assert(it2.depth() == it.depth());
158 assert(it2.recursion_pending() == it.recursion_pending());
159 assert(*it2 == *it);
161 it = std::move(it);
162 assert(it2.options() == it.options());
163 assert(it2.depth() == it.depth());
164 assert(it2.recursion_pending() == it.recursion_pending());
165 assert(*it2 == *it);
168 int main(int, char**) {
169 test_assignment_signature();
170 test_move_to_end_iterator();
171 test_move_from_end_iterator();
172 test_move_valid_iterator();
173 test_returns_reference_to_self();
174 test_self_move();
176 return 0;