path.pass.cpp (2633B)
1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: c++98, c++03 11 12 // <filesystem> 13 14 // class directory_entry 15 16 // const path& path() const noexcept; 17 // operator const path&() const noexcept; 18 19 #include "filesystem_include.hpp" 20 #include <type_traits> 21 #include <cassert> 22 23 24 void test_path_method() { 25 using namespace fs; 26 const path p("foo/bar/baz.exe"); 27 const path p2("abc"); 28 { 29 directory_entry nce; 30 const directory_entry e(""); 31 static_assert(std::is_same<decltype(e.path()), const path&>::value, ""); 32 static_assert(std::is_same<decltype(nce.path()), const path&>::value, ""); 33 static_assert(noexcept(e.path()) && noexcept(nce.path()), ""); 34 } 35 { 36 directory_entry e(p); 37 path const& pref = e.path(); 38 assert(pref == p); 39 assert(&pref == &e.path()); 40 e.assign(p2); 41 assert(pref == p2); 42 assert(&pref == &e.path()); 43 } 44 } 45 46 void test_path_conversion() { 47 using namespace fs; 48 const path p("foo/bar/baz.exe"); 49 const path p2("abc"); 50 { 51 directory_entry nce; 52 const directory_entry e(""); 53 // Check conversions exist 54 static_assert(std::is_convertible<directory_entry&, path const&>::value, ""); 55 static_assert(std::is_convertible<directory_entry const&, path const&>::value, ""); 56 static_assert(std::is_convertible<directory_entry &&, path const&>::value, ""); 57 static_assert(std::is_convertible<directory_entry const&&, path const&>::value, ""); 58 // Not convertible to non-const 59 static_assert(!std::is_convertible<directory_entry&, path&>::value, ""); 60 static_assert(!std::is_convertible<directory_entry const&, path&>::value, ""); 61 static_assert(!std::is_convertible<directory_entry &&, path&>::value, ""); 62 static_assert(!std::is_convertible<directory_entry const&&, path&>::value, ""); 63 // conversions are noexcept 64 static_assert(noexcept(e.operator fs::path const&()) && 65 noexcept(e.operator fs::path const&()), ""); 66 } 67 // const 68 { 69 directory_entry const e(p); 70 path const& pref = e; 71 assert(&pref == &e.path()); 72 } 73 // non-const 74 { 75 directory_entry e(p); 76 path const& pref = e; 77 assert(&pref == &e.path()); 78 79 e.assign(p2); 80 assert(pref == p2); 81 assert(&pref == &e.path()); 82 } 83 } 84 85 int main() { 86 test_path_method(); 87 test_path_conversion(); 88 }