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 //===----------------------------------------------------------------------===//
8 
9 // REQUIRES: can-create-symlinks
10 // UNSUPPORTED: c++03, c++11, c++14
11 
12 // <filesystem>
13 
14 // class directory_entry
15 
16 // directory_entry(directory_entry&&) noexcept = default;
17 
18 #include <filesystem>
19 #include <type_traits>
20 #include <cassert>
21 
22 #include "test_macros.h"
23 #include "filesystem_test_helper.h"
24 #include "test_convertible.h"
25 namespace fs = std::filesystem;
26 
move_ctor()27 static void move_ctor() {
28   using namespace fs;
29   // Move
30   {
31     static_assert(std::is_nothrow_move_constructible<directory_entry>::value,
32                   "directory_entry must be nothrow move constructible");
33     const path p("foo/bar/baz");
34     directory_entry e(p);
35     assert(e.path() == p);
36     directory_entry e2(std::move(e));
37     assert(e2.path() == p);
38     assert(e.path() != p); // Testing moved from state.
39   }
40 }
41 
move_ctor_copies_cache()42 static void move_ctor_copies_cache() {
43   using namespace fs;
44   scoped_test_env env;
45   const path dir = env.create_dir("dir");
46   const path file = env.create_file("dir/file", 42);
47   const path sym = env.create_symlink("dir/file", "sym");
48 
49   {
50     directory_entry ent(sym);
51 
52     fs::remove(sym);
53 
54     directory_entry ent_cp(std::move(ent));
55     assert(ent_cp.path() == sym);
56     assert(ent_cp.is_symlink());
57   }
58 
59   {
60     directory_entry ent(file);
61 
62     fs::remove(file);
63 
64     directory_entry ent_cp(std::move(ent));
65     assert(ent_cp.path() == file);
66     assert(ent_cp.is_regular_file());
67   }
68 }
69 
main(int,char **)70 int main(int, char**) {
71   move_ctor();
72   move_ctor_copies_cache();
73 
74   return 0;
75 }
76