[libc++] Expand the contents of LIBCXX_ENABLE_FILESYSTEM

Since LIBCXX_ENABLE_FILESYSTEM now truly represents whether the
platform supports a filesystem (as opposed to whether the <filesystem>
library is provided), we can provide a few additional classes from
the <filesystem> library even when the platform does not have support
for a filesystem. For example, this allows performing path manipulations
using std::filesystem::path even on platforms where there is no actual
filesystem.

rdar://107061236

Differential Revision: https://reviews.llvm.org/D152382
This commit is contained in:
Louis Dionne 2023-06-05 12:53:42 -07:00
parent 431c49d6b6
commit c352fa7407
152 changed files with 440 additions and 299 deletions

View File

@ -67,6 +67,10 @@ Improvements and New Features
in the specialization has not been implemented in libc++. This prevents the
feature-test macro to be set.
- Platforms that don't have support for a filesystem can now still take advantage of some parts of ``<filesystem>``.
Anything that does not rely on having an actual filesystem available will now work, such as ``std::filesystem::path``,
``std::filesystem::perms`` and similar classes.
Deprecations and Removals
-------------------------

View File

@ -21,8 +21,6 @@
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH
enum class _LIBCPP_ENUM_VIS copy_options : unsigned short {
none = 0,
skip_existing = 1,
@ -75,8 +73,6 @@ inline copy_options& operator^=(copy_options& __lhs, copy_options __rhs) {
return __lhs = __lhs ^ __rhs;
}
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP
_LIBCPP_END_NAMESPACE_FILESYSTEM
#endif // _LIBCPP_CXX03_LANG

View File

@ -35,13 +35,12 @@
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
#ifndef _LIBCPP_CXX03_LANG
#if !defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH
class directory_entry {
typedef _VSTD_FS::path _Path;
@ -520,7 +519,7 @@ _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP
_LIBCPP_END_NAMESPACE_FILESYSTEM
#endif // _LIBCPP_CXX03_LANG
#endif // !defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
_LIBCPP_POP_MACROS

View File

@ -29,7 +29,7 @@
# pragma GCC system_header
#endif
#ifndef _LIBCPP_CXX03_LANG
#if !defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
@ -164,6 +164,6 @@ inline constexpr bool _VSTD::ranges::enable_view<_VSTD_FS::directory_iterator> =
#endif // _LIBCPP_STD_VER >= 20
#endif // _LIBCPP_CXX03_LANG
#endif // !defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
#endif // _LIBCPP___FILESYSTEM_DIRECTORY_ITERATOR_H

View File

@ -21,8 +21,6 @@
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH
enum class _LIBCPP_ENUM_VIS directory_options : unsigned char {
none = 0,
follow_directory_symlink = 1,
@ -73,8 +71,6 @@ inline directory_options& operator^=(directory_options& __lhs,
return __lhs = __lhs ^ __rhs;
}
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP
_LIBCPP_END_NAMESPACE_FILESYSTEM
#endif // _LIBCPP_CXX03_LANG

View File

@ -23,8 +23,6 @@
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH
class _LIBCPP_EXPORTED_FROM_ABI file_status {
public:
// constructors
@ -71,8 +69,6 @@ private:
perms __prms_;
};
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP
_LIBCPP_END_NAMESPACE_FILESYSTEM
#endif // _LIBCPP_CXX03_LANG

View File

@ -70,22 +70,19 @@ private:
shared_ptr<_Storage> __storage_;
};
// TODO(ldionne): We need to pop the pragma and push it again after
// filesystem_error to work around PR41078.
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH
# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
template <class... _Args>
_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_filesystem_error(_Args&&... __args) {
_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY void
__throw_filesystem_error(_Args&&... __args) {
throw filesystem_error(_VSTD::forward<_Args>(__args)...);
}
# else
template <class... _Args>
_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_filesystem_error(_Args&&...) {
_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY void
__throw_filesystem_error(_Args&&...) {
_LIBCPP_VERBOSE_ABORT("filesystem_error was thrown in -fno-exceptions mode");
}
# endif
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP
_LIBCPP_END_NAMESPACE_FILESYSTEM

View File

@ -28,7 +28,7 @@
# pragma GCC system_header
#endif
#ifndef _LIBCPP_CXX03_LANG
#if !defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
@ -196,6 +196,6 @@ _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP
_LIBCPP_END_NAMESPACE_FILESYSTEM
#endif // _LIBCPP_CXX03_LANG
#endif // !defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
#endif // _LIBCPP___FILESYSTEM_OPERATIONS_H

View File

@ -27,8 +27,6 @@
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH
class _LIBCPP_EXPORTED_FROM_ABI path::iterator {
public:
enum _ParserState : unsigned char {
@ -114,19 +112,19 @@ private:
_ParserState __state_;
};
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY
inline _LIBCPP_INLINE_VISIBILITY bool operator==(const path::iterator& __lhs,
const path::iterator& __rhs) {
return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
__lhs.__entry_.data() == __rhs.__entry_.data();
}
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY
inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path::iterator& __lhs,
const path::iterator& __rhs) {
return !(__lhs == __rhs);
}
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP
_LIBCPP_END_NAMESPACE_FILESYSTEM
#endif // _LIBCPP_CXX03_LANG

View File

@ -21,8 +21,6 @@
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH
enum class _LIBCPP_ENUM_VIS perm_options : unsigned char {
replace = 1,
add = 2,
@ -68,8 +66,6 @@ inline perm_options& operator^=(perm_options& __lhs, perm_options __rhs) {
return __lhs = __lhs ^ __rhs;
}
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP
_LIBCPP_END_NAMESPACE_FILESYSTEM
#endif // _LIBCPP_CXX03_LANG

View File

@ -21,8 +21,6 @@
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH
// On Windows, these permission bits map to one single readonly flag per
// file, and the executable bit is always returned as set. When setting
// permissions, as long as the write bit is set for either owner, group or
@ -86,8 +84,6 @@ inline perms& operator|=(perms& __lhs, perms __rhs) { return __lhs = __lhs | __r
_LIBCPP_INLINE_VISIBILITY
inline perms& operator^=(perms& __lhs, perms __rhs) { return __lhs = __lhs ^ __rhs; }
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP
_LIBCPP_END_NAMESPACE_FILESYSTEM
#endif // _LIBCPP_CXX03_LANG

View File

@ -28,7 +28,7 @@
# pragma GCC system_header
#endif
#ifndef _LIBCPP_CXX03_LANG
#if !defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
@ -178,6 +178,6 @@ inline constexpr bool _VSTD::ranges::enable_view<_VSTD_FS::recursive_directory_i
#endif // _LIBCPP_STD_VER >= 20
#endif // _LIBCPP_CXX03_LANG
#endif // !defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
#endif // _LIBCPP___FILESYSTEM_RECURSIVE_DIRECTORY_ITERATOR_H

View File

@ -22,8 +22,6 @@
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH
struct _LIBCPP_EXPORTED_FROM_ABI space_info {
uintmax_t capacity;
uintmax_t free;
@ -34,8 +32,6 @@ struct _LIBCPP_EXPORTED_FROM_ABI space_info {
# endif
};
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP
_LIBCPP_END_NAMESPACE_FILESYSTEM
#endif // _LIBCPP_CXX03_LANG

View File

@ -558,10 +558,6 @@ inline constexpr bool std::ranges::enable_view<std::filesystem::recursive_direct
// [fs.filesystem.syn]
#include <compare>
#if defined(_LIBCPP_HAS_NO_FILESYSTEM)
# error "The <filesystem> library is not supported since libc++ has been configured without support for a filesystem."
#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

View File

@ -189,15 +189,12 @@ typedef basic_fstream<wchar_t> wfstream;
#include <__utility/swap.h>
#include <__utility/unreachable.h>
#include <cstdio>
#include <filesystem>
#include <istream>
#include <ostream>
#include <typeinfo>
#include <version>
#if !defined(_LIBCPP_HAS_NO_FILESYSTEM)
# include <filesystem>
#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

View File

@ -911,6 +911,7 @@ module std [system] {
private header "__filesystem/path.h"
export functional.__functional.hash
export functional.__functional.unary_function
export string
}
module path_iterator { private header "__filesystem/path_iterator.h" }
module perm_options { private header "__filesystem/perm_options.h" }

View File

@ -12,6 +12,10 @@ set(LIBCXX_SOURCES
condition_variable.cpp
condition_variable_destructor.cpp
exception.cpp
filesystem/filesystem_clock.cpp
filesystem/filesystem_error.cpp
filesystem/path_parser.h
filesystem/path.cpp
functional.cpp
future.cpp
hash.cpp
@ -113,11 +117,7 @@ if (LIBCXX_ENABLE_FILESYSTEM)
filesystem/directory_entry.cpp
filesystem/directory_iterator.cpp
filesystem/file_descriptor.h
filesystem/filesystem_clock.cpp
filesystem/filesystem_error.cpp
filesystem/operations.cpp
filesystem/path_parser.h
filesystem/path.cpp
filesystem/posix_compat.h
filesystem/time_utils.h
)

View File

@ -5,6 +5,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <fstream>
// template <class charT, class traits = char_traits<charT> >

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// UNSUPPORTED: no-filesystem
// ADDITIONAL_COMPILE_FLAGS: -I %S/../../../../../../src
// This test relies on calling functions from the libcxx internal headers

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// These tests require locale for non-char paths
// UNSUPPORTED: no-localization
@ -24,11 +25,11 @@
#include <type_traits>
#include <cassert>
#include "test_macros.h"
#include "test_iterators.h"
#include "count_new.h"
#include "make_string.h"
#include "min_allocator.h"
#include "filesystem_test_helper.h"
#include "test_iterators.h"
#include "test_macros.h"
// the SSO is always triggered for strings of size 2.

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -1,7 +0,0 @@
# Load the same local configuration as the filesystem tests in libcxx/test/std
import os
std_filesystem_tests = os.path.join(
config.test_source_root, "std", "input.output", "filesystems"
)
config.load_from_path(os.path.join(std_filesystem_tests, "lit.local.cfg"), lit_config)

View File

@ -63,8 +63,8 @@ else:
//--- {header}.sh.cpp
{lit_header_restrictions.get(header, '')}
// TODO: Fix this test to make it work with filesystem, localization or wide characters disabled
// UNSUPPORTED{BLOCKLIT}: no-filesystem, no-localization, no-wide-characters
// TODO: Fix this test to make it work with localization or wide characters disabled
// UNSUPPORTED{BLOCKLIT}: no-localization, no-wide-characters
// When built with modules, this test doesn't work because --trace-includes doesn't
// report the stack of includes correctly.

View File

@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: no-filesystem
// XFAIL: availability-filesystem-missing
// Make sure the various containers' iterators are not broken by the use of `std::rel_ops`.
@ -15,6 +14,7 @@
#include <array>
#include <deque>
#include <filesystem>
#include <forward_list>
#include <list>
#include <map>
@ -26,10 +26,6 @@
#include "test_macros.h"
#if TEST_STD_VER >= 11
#include "filesystem_include.h"
#endif
#if TEST_STD_VER >= 17
#include <string_view>
#endif
@ -115,16 +111,18 @@ template void test_forward<std::unordered_multiset<int> >();
template void test_forward<std::unordered_set<int> >();
template void test_random_access<std::vector<int> >();
#if TEST_STD_VER >= 11
#if TEST_STD_VER >= 17
void test_directory_iterators() {
fs::directory_iterator it;
#ifndef TEST_HAS_NO_FILESYSTEM
std::filesystem::directory_iterator it;
test_eq(it, it);
fs::recursive_directory_iterator rdit;
std::filesystem::recursive_directory_iterator rdit;
test_eq(rdit, rdit);
#endif
}
template void test_forward<fs::path>();
template void test_forward<std::filesystem::path>();
#endif
#if TEST_STD_VER >= 17

View File

@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing

View File

@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing

View File

@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing

View File

@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing

View File

@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing

View File

@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing

View File

@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// directory_iterator, recursive_directory_iterator

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// directory_iterator

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: availability-filesystem-missing
// UNSUPPORTED: c++03
// <filesystem>

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -24,7 +25,36 @@
#include <type_traits>
#include "test_macros.h"
#include "filesystem_test_helper.h"
template <class Iter1, class Iter2>
bool checkCollectionsEqual(
Iter1 start1, Iter1 const end1
, Iter2 start2, Iter2 const end2
)
{
while (start1 != end1 && start2 != end2) {
if (*start1 != *start2) {
return false;
}
++start1; ++start2;
}
return (start1 == end1 && start2 == end2);
}
template <class Iter1, class Iter2>
bool checkCollectionsEqualBackwards(
Iter1 const start1, Iter1 end1
, Iter2 const start2, Iter2 end2
)
{
while (start1 != end1 && start2 != end2) {
--end1; --end2;
if (*end1 != *end2) {
return false;
}
}
return (start1 == end1 && start2 == end2);
}
void checkIteratorConcepts() {
using namespace fs;

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// These tests require locale for non-char paths
// UNSUPPORTED: no-localization
@ -33,11 +34,11 @@
// to an intermediate path object, causing allocations in cases where no
// allocations are done on other platforms.
#include "test_macros.h"
#include "test_iterators.h"
#include "../path_helper.h"
#include "count_new.h"
#include "filesystem_test_helper.h"
#include "make_string.h"
#include "test_iterators.h"
#include "test_macros.h"
struct AppendOperatorTestcase {
MultiStringType lhs;

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// These tests require locale for non-char paths
// UNSUPPORTED: no-localization
@ -32,10 +33,11 @@
// On Windows, charset conversions cause allocations in the path class in
// cases where no allocations are done on other platforms.
#include "test_macros.h"
#include "test_iterators.h"
#include "../../path_helper.h"
#include "count_new.h"
#include "filesystem_test_helper.h"
#include "make_string.h"
#include "test_iterators.h"
#include "test_macros.h"
template <class CharT>

View File

@ -8,6 +8,7 @@
// UNSUPPORTED: no-localization
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
// <filesystem>
@ -37,7 +38,10 @@
#include <cassert>
#include "test_macros.h"
#include "filesystem_test_helper.h"
#ifdef _WIN32
# include <windows.h> // SetFileApisToANSI & friends
#endif
// Test conversion with strings that fit within the latin1 charset, that fit
// within one code point in UTF-16, and that can be expressible in certain

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -28,15 +29,16 @@
// template<> struct hash<filesystem::path>;
#include "filesystem_include.h"
#include <cassert>
#include <string>
#include <type_traits>
#include <vector>
#include <cassert>
#include "test_macros.h"
#include "assert_macros.h"
#include "count_new.h"
#include "test_comparisons.h"
#include "test_iterators.h"
#include "count_new.h"
#include "filesystem_test_helper.h"
#include "test_macros.h"
struct PathCompareTest {
const char* LHS;

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// These tests require locale for non-char paths
// UNSUPPORTED: no-localization
@ -39,10 +40,11 @@
// On Windows, charset conversions cause allocations in the path class in
// cases where no allocations are done on other platforms.
#include "test_macros.h"
#include "test_iterators.h"
#include "../path_helper.h"
#include "count_new.h"
#include "filesystem_test_helper.h"
#include "make_string.h"
#include "test_iterators.h"
#include "test_macros.h"
struct ConcatOperatorTestcase {

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// These tests require locale for non-char paths
// UNSUPPORTED: no-localization
@ -25,10 +26,11 @@
#include <type_traits>
#include <cassert>
#include "test_macros.h"
#include "test_iterators.h"
#include "../../path_helper.h"
#include "make_string.h"
#include "min_allocator.h"
#include "filesystem_test_helper.h"
#include "test_iterators.h"
#include "test_macros.h"
template <class CharT, class ...Args>

View File

@ -13,6 +13,7 @@
// bool empty() const noexcept;
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: availability-filesystem-missing
#include "filesystem_include.h"

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -48,13 +49,13 @@
#include <cassert>
#include <cstddef>
#include <iterator>
#include <string>
#include <type_traits>
#include <vector>
#include "test_macros.h"
#include "test_iterators.h"
#include "count_new.h"
#include "filesystem_test_helper.h"
struct ComparePathExact {
bool operator()(fs::path const& LHS, std::string const& RHS) const {

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -18,9 +19,9 @@
#include <cstdio>
#include <string>
#include "test_macros.h"
#include "../../path_helper.h"
#include "count_new.h"
#include "filesystem_test_helper.h"
#include "test_macros.h"
int main(int, char**) {

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -19,10 +20,9 @@
#include <cstdio>
#include <string>
#include "test_macros.h"
#include "../../path_helper.h"
#include "count_new.h"
#include "filesystem_test_helper.h"
#include "test_macros.h"
int main(int, char**) {
// clang-format off

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// These tests require locale for non-char paths
// UNSUPPORTED: no-localization
@ -21,18 +22,19 @@
// generic_string(const Allocator& a = Allocator()) const;
#include "filesystem_include.h"
#include <type_traits>
#include <cassert>
#include <string>
#include <type_traits>
#include "test_macros.h"
#include "test_iterators.h"
#include "count_new.h"
#include "make_string.h"
#include "min_allocator.h"
#include "filesystem_test_helper.h"
#include "test_iterators.h"
#include "test_macros.h"
MultiStringType longString = MKSTR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/123456789/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
// generic_string<C, T, A> forwards to string<C, T, A>. Tests for
// string<C, T, A>() are in "path.native.obs/string_alloc.pass.cpp".
// generic_string is minimally tested here.

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// These tests require locale for non-char paths
// UNSUPPORTED: no-localization
@ -23,14 +24,15 @@
#include "filesystem_include.h"
#include <type_traits>
#include <cassert>
#include <string>
#include <type_traits>
#include "test_macros.h"
#include "test_iterators.h"
#include "count_new.h"
#include "make_string.h"
#include "min_allocator.h"
#include "filesystem_test_helper.h"
#include "test_iterators.h"
#include "test_macros.h"
MultiStringType input = MKSTR("c:\\foo\\bar");
#ifdef _WIN32

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -15,13 +16,12 @@
// void clear() noexcept
#include "filesystem_include.h"
#include <type_traits>
#include <cassert>
#include <type_traits>
#include "test_macros.h"
#include "test_iterators.h"
#include "assert_macros.h"
#include "count_new.h"
#include "filesystem_test_helper.h"
#include "test_iterators.h"
int main(int, char**) {

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -15,13 +16,12 @@
// path& make_preferred()
#include "filesystem_include.h"
#include <type_traits>
#include <cassert>
#include <string>
#include <type_traits>
#include "test_macros.h"
#include "test_iterators.h"
#include "count_new.h"
#include "filesystem_test_helper.h"
struct MakePreferredTestcase {

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -18,10 +19,8 @@
#include <type_traits>
#include <cassert>
#include "test_macros.h"
#include "test_iterators.h"
#include "count_new.h"
#include "filesystem_test_helper.h"
struct RemoveFilenameTestcase {
const char* value;

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -15,13 +16,12 @@
// path& replace_extension(path const& p = path())
#include "filesystem_include.h"
#include <type_traits>
#include <cassert>
#include <string>
#include <type_traits>
#include "test_macros.h"
#include "test_iterators.h"
#include "count_new.h"
#include "filesystem_test_helper.h"
#include "test_iterators.h"
struct ReplaceExtensionTestcase {

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -15,13 +16,12 @@
// path& replace_filename( const path& replacement );
#include "filesystem_include.h"
#include <type_traits>
#include <cassert>
#include <string>
#include <type_traits>
#include "test_macros.h"
#include "test_iterators.h"
#include "count_new.h"
#include "filesystem_test_helper.h"
struct ReplaceFilenameTestcase {
const char* value;

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -15,13 +16,12 @@
// void swap(path& rhs) noexcept;
#include "filesystem_include.h"
#include <type_traits>
#include <cassert>
#include <type_traits>
#include "test_macros.h"
#include "test_iterators.h"
#include "assert_macros.h"
#include "count_new.h"
#include "filesystem_test_helper.h"
#include "test_iterators.h"
struct SwapTestcase {

View File

@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -16,16 +17,15 @@
// const value_type* c_str() const noexcept;
#include "filesystem_include.h"
#include <type_traits>
#include <cassert>
#include <string>
#include <type_traits>
#include "assert_macros.h"
#include "test_macros.h"
#include "filesystem_test_helper.h"
int main(int, char**)
{
int main(int, char**) {
using namespace fs;
const char* const value = "hello world";
const std::string str_value = value;

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// These tests require locale for non-char paths
// UNSUPPORTED: no-localization
@ -23,14 +24,16 @@
#include "filesystem_include.h"
#include <type_traits>
#include <cassert>
#include <string>
#include <type_traits>
#include "test_macros.h"
#include "test_iterators.h"
#include "assert_macros.h"
#include "count_new.h"
#include "make_string.h"
#include "min_allocator.h"
#include "filesystem_test_helper.h"
#include "test_iterators.h"
#include "test_macros.h"
MultiStringType longString = MKSTR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/123456789/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -15,15 +16,15 @@
// const string_type& native() const noexcept;
#include "filesystem_include.h"
#include <type_traits>
#include <cassert>
#include <string>
#include <type_traits>
#include "assert_macros.h"
#include "test_macros.h"
#include "filesystem_test_helper.h"
int main(int, char**)
{
int main(int, char**) {
using namespace fs;
const char* const value = "hello world";
std::string value_str(value);

View File

@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -16,15 +17,15 @@
// operator string_type() const;
#include "filesystem_include.h"
#include <type_traits>
#include <cassert>
#include <string>
#include <type_traits>
#include "assert_macros.h"
#include "test_macros.h"
#include "filesystem_test_helper.h"
int main(int, char**)
{
int main(int, char**) {
using namespace fs;
using string_type = path::string_type;
const char* const value = "hello world";

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -17,11 +18,9 @@
#include <cassert>
#include "test_macros.h"
#include "filesystem_test_helper.h"
// This is mainly tested via the member append functions.
int main(int, char**)
{
int main(int, char**) {
using namespace fs;
path p1("abc");
path p2("def");

View File

@ -7,10 +7,10 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
#include "filesystem_include.h"
using namespace fs;

View File

@ -8,6 +8,7 @@
// UNSUPPORTED: c++03
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -17,13 +18,13 @@
// path u8path(InputIter, InputIter);
#include "filesystem_include.h"
#include <type_traits>
#include <cassert>
#include <string>
#include <type_traits>
#include "test_macros.h"
#include "test_iterators.h"
#include "count_new.h"
#include "filesystem_test_helper.h"
int main(int, char**)

View File

@ -8,6 +8,7 @@
// UNSUPPORTED: c++03
// UNSUPPORTED: no-localization
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -28,10 +29,10 @@
#include <cassert>
#include <iostream>
#include "test_macros.h"
#include "test_iterators.h"
#include "count_new.h"
#include "filesystem_test_helper.h"
#include "make_string.h"
#include "test_iterators.h"
#include "test_macros.h"
MultiStringType InStr = MKSTR("abcdefg/\"hijklmnop\"/qrstuvwxyz/123456789");
MultiStringType OutStr = MKSTR("\"abcdefg/\\\"hijklmnop\\\"/qrstuvwxyz/123456789\"");

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>
@ -18,7 +19,6 @@
#include "test_macros.h"
#include "count_new.h"
#include "filesystem_test_helper.h"
// NOTE: this is tested in path.members/path.modifiers via the member swap.
int main(int, char**)

View File

@ -0,0 +1,101 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef TEST_STD_INPUT_OUTPUT_FILESYSTEMS_CLASS_PATH_PATH_HELPER_H
#define TEST_STD_INPUT_OUTPUT_FILESYSTEMS_CLASS_PATH_PATH_HELPER_H
#include <cstddef>
#include <iterator>
#include "filesystem_include.h"
#include "make_string.h"
// Testing the allocation behavior of the code_cvt functions requires
// *knowing* that the allocation was not done by "path::__str_".
// This hack forces path to allocate enough memory.
inline void PathReserve(fs::path& p, std::size_t N) {
auto const& native_ref = p.native();
const_cast<fs::path::string_type&>(native_ref).reserve(N);
}
inline bool PathEq(fs::path const& LHS, fs::path const& RHS) {
return LHS.native() == RHS.native();
}
inline bool PathEqIgnoreSep(fs::path LHS, fs::path RHS) {
LHS.make_preferred();
RHS.make_preferred();
return LHS.native() == RHS.native();
}
template <class Iter>
Iter IterEnd(Iter B) {
using VT = typename std::iterator_traits<Iter>::value_type;
for (; *B != VT{}; ++B)
;
return B;
}
template <class CharT>
const CharT* StrEnd(CharT const* P) {
return IterEnd(P);
}
template <class CharT>
std::size_t StrLen(CharT const* P) {
return StrEnd(P) - P;
}
const MultiStringType PathList[] = {
MKSTR(""),
MKSTR(" "),
MKSTR("//"),
MKSTR("."),
MKSTR(".."),
MKSTR("foo"),
MKSTR("/"),
MKSTR("/foo"),
MKSTR("foo/"),
MKSTR("/foo/"),
MKSTR("foo/bar"),
MKSTR("/foo/bar"),
MKSTR("//net"),
MKSTR("//net/foo"),
MKSTR("///foo///"),
MKSTR("///foo///bar"),
MKSTR("/."),
MKSTR("./"),
MKSTR("/.."),
MKSTR("../"),
MKSTR("foo/."),
MKSTR("foo/.."),
MKSTR("foo/./"),
MKSTR("foo/./bar"),
MKSTR("foo/../"),
MKSTR("foo/../bar"),
MKSTR("c:"),
MKSTR("c:/"),
MKSTR("c:foo"),
MKSTR("c:/foo"),
MKSTR("c:foo/"),
MKSTR("c:/foo/"),
MKSTR("c:/foo/bar"),
MKSTR("prn:"),
MKSTR("c:\\"),
MKSTR("c:\\foo"),
MKSTR("c:foo\\"),
MKSTR("c:\\foo\\"),
MKSTR("c:\\foo/"),
MKSTR("c:/foo\\bar"),
MKSTR("//"),
MKSTR("/finally/we/need/one/really/really/really/really/really/really/really/long/string")
};
const unsigned PathListSize = sizeof(PathList) / sizeof(MultiStringType);
#endif // TEST_STD_INPUT_OUTPUT_FILESYSTEMS_CLASS_PATH_PATH_HELPER_H

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: availability-filesystem-missing
// path
@ -16,7 +17,6 @@
#include <ranges>
static_assert(std::same_as<std::ranges::iterator_t<fs::path>, fs::path::iterator>);
static_assert(std::ranges::common_range<fs::path>);
static_assert(std::ranges::bidirectional_range<fs::path>);

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// recursive_directory_iterator

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: no-filesystem
// UNSUPPORTED: availability-filesystem-missing
// <filesystem>

Some files were not shown because too many files have changed in this diff Show More