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 // UNSUPPORTED: c++03, c++11, c++14
10
11 // <filesystem>
12
13 // class directory_entry
14
15 // const path& path() const noexcept;
16 // operator const path&() const noexcept;
17
18 #include <filesystem>
19 #include <type_traits>
20 #include <cassert>
21
22 #include "test_macros.h"
23 namespace fs = std::filesystem;
24
test_path_method()25 void test_path_method() {
26 using namespace fs;
27 const path p("foo/bar/baz.exe");
28 const path p2("abc");
29 {
30 directory_entry nce;
31 const directory_entry e("");
32 static_assert(std::is_same<decltype(e.path()), const path&>::value, "");
33 static_assert(std::is_same<decltype(nce.path()), const path&>::value, "");
34 static_assert(noexcept(e.path()) && noexcept(nce.path()), "");
35 }
36 {
37 directory_entry e(p);
38 path const& pref = e.path();
39 assert(pref == p);
40 assert(&pref == &e.path());
41 e.assign(p2);
42 assert(pref == p2);
43 assert(&pref == &e.path());
44 }
45 }
46
test_path_conversion()47 void test_path_conversion() {
48 using namespace fs;
49 const path p("foo/bar/baz.exe");
50 const path p2("abc");
51 {
52 directory_entry nce;
53 const directory_entry e("");
54 // Check conversions exist
55 static_assert(std::is_convertible<directory_entry&, path const&>::value, "");
56 static_assert(std::is_convertible<directory_entry const&, path const&>::value, "");
57 static_assert(std::is_convertible<directory_entry &&, path const&>::value, "");
58 static_assert(std::is_convertible<directory_entry const&&, path const&>::value, "");
59 // Not convertible to non-const
60 static_assert(!std::is_convertible<directory_entry&, path&>::value, "");
61 static_assert(!std::is_convertible<directory_entry const&, path&>::value, "");
62 static_assert(!std::is_convertible<directory_entry &&, path&>::value, "");
63 static_assert(!std::is_convertible<directory_entry const&&, path&>::value, "");
64 // conversions are noexcept
65 static_assert(noexcept(e.operator fs::path const&()) &&
66 noexcept(e.operator fs::path const&()), "");
67 }
68 // const
69 {
70 directory_entry const e(p);
71 path const& pref = e;
72 assert(&pref == &e.path());
73 }
74 // non-const
75 {
76 directory_entry e(p);
77 path const& pref = e;
78 assert(&pref == &e.path());
79
80 e.assign(p2);
81 assert(pref == p2);
82 assert(&pref == &e.path());
83 }
84 }
85
main(int,char **)86 int main(int, char**) {
87 test_path_method();
88 test_path_conversion();
89
90 return 0;
91 }
92