From e96d6a1fb70d717c5bfb0a1bc3b7e787b709e033 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Mon, 2 Apr 2018 23:35:24 +0000 Subject: [PATCH] Implement P0430R2 - File system library on non-POSIX systems. This patch implements P0430R2, who's largest change is adding the path::format enumeration for supporting path format conversions in path constructors. However, since libc++'s filesystem only really supports POSIX like systems, there are no real changes needed. This patch simply adds the format enum and then ignores it when it's passed to constructors. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@329031 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/experimental/filesystem | 19 +++++++--- .../path.construct/source.pass.cpp | 24 ++++++++---- .../fs.enum/enum.path.format.pass.cpp | 38 +++++++++++++++++++ www/cxx1z_status.html | 2 +- 4 files changed, 69 insertions(+), 14 deletions(-) create mode 100644 test/std/experimental/filesystem/fs.enum/enum.path.format.pass.cpp diff --git a/include/experimental/filesystem b/include/experimental/filesystem index 411b98121..a8518249d 100644 --- a/include/experimental/filesystem +++ b/include/experimental/filesystem @@ -721,24 +721,31 @@ public: typedef _VSTD::string_view __string_view; static _LIBCPP_CONSTEXPR value_type preferred_separator = '/'; + enum class _LIBCPP_ENUM_VIS format : unsigned char { + auto_format, + native_format, + generic_format + }; + // constructors and destructor _LIBCPP_INLINE_VISIBILITY path() _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {} _LIBCPP_INLINE_VISIBILITY path(path&& __p) _NOEXCEPT : __pn_(_VSTD::move(__p.__pn_)) {} _LIBCPP_INLINE_VISIBILITY - path(string_type&& __s) _NOEXCEPT : __pn_(_VSTD::move(__s)) {} + path(string_type&& __s, format = format::auto_format) _NOEXCEPT + : __pn_(_VSTD::move(__s)) {} template < class _Source, class = _EnableIfPathable<_Source, void> > - path(const _Source& __src) { + path(const _Source& __src, format = format::auto_format) { _SourceCVT<_Source>::__append_source(__pn_, __src); } template - path(_InputIt __first, _InputIt __last) { + path(_InputIt __first, _InputIt __last, format = format::auto_format) { typedef typename iterator_traits<_InputIt>::value_type _ItVal; _PathCVT<_ItVal>::__append_range(__pn_, __first, __last); } @@ -747,9 +754,11 @@ public: template > - path(const _Source& __src, const locale& __loc); + path(const _Source& __src, const locale& __loc, + format = format::auto_format); template - path(_InputIt __first, _InputIt _last, const locale& __loc); + path(_InputIt __first, _InputIt _last, const locale& __loc, + format = format::auto_format); _LIBCPP_INLINE_VISIBILITY ~path() = default; diff --git a/test/std/experimental/filesystem/class.path/path.member/path.construct/source.pass.cpp b/test/std/experimental/filesystem/class.path/path.member/path.construct/source.pass.cpp index e80ae45b8..a7c14f3ce 100644 --- a/test/std/experimental/filesystem/class.path/path.member/path.construct/source.pass.cpp +++ b/test/std/experimental/filesystem/class.path/path.member/path.construct/source.pass.cpp @@ -29,8 +29,8 @@ #include "filesystem_test_helper.hpp" -template -void RunTestCase(MultiStringType const& MS) { +template +void RunTestCaseImpl(MultiStringType const& MS, Args... args) { using namespace fs; const char* Expect = MS; const CharT* TestPath = MS; @@ -41,44 +41,52 @@ void RunTestCase(MultiStringType const& MS) { // StringTypes { const std::basic_string S(TestPath); - path p(S); + path p(S, args...); assert(p.native() == Expect); assert(p.string() == TestPath); assert(p.string() == S); } { const std::basic_string_view S(TestPath); - path p(S); + path p(S, args...); assert(p.native() == Expect); assert(p.string() == TestPath); assert(p.string() == S); } // Char* pointers { - path p(TestPath); + path p(TestPath, args...); assert(p.native() == Expect); assert(p.string() == TestPath); } { - path p(TestPath, TestPathEnd); + path p(TestPath, TestPathEnd, args...); assert(p.native() == Expect); assert(p.string() == TestPath); } // Iterators { using It = input_iterator; - path p(It{TestPath}); + path p(It{TestPath}, args...); assert(p.native() == Expect); assert(p.string() == TestPath); } { using It = input_iterator; - path p(It{TestPath}, It{TestPathEnd}); + path p(It{TestPath}, It{TestPathEnd}, args...); assert(p.native() == Expect); assert(p.string() == TestPath); } } +template +void RunTestCase(MultiStringType const& MS) { + RunTestCaseImpl(MS); + RunTestCaseImpl(MS, fs::path::format::auto_format); + RunTestCaseImpl(MS, fs::path::format::native_format); + RunTestCaseImpl(MS, fs::path::format::generic_format); +} + void test_sfinae() { using namespace fs; { diff --git a/test/std/experimental/filesystem/fs.enum/enum.path.format.pass.cpp b/test/std/experimental/filesystem/fs.enum/enum.path.format.pass.cpp new file mode 100644 index 000000000..51e3f86ea --- /dev/null +++ b/test/std/experimental/filesystem/fs.enum/enum.path.format.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// + +// class path; +// enum class format; + +#include "filesystem_include.hpp" +#include +#include + +#include "test_macros.h" + +int main() { + typedef fs::path::format E; + static_assert(std::is_enum::value, ""); + + // Check that E is a scoped enum by checking for conversions. + typedef std::underlying_type::type UT; + static_assert(!std::is_convertible::value, ""); + + LIBCPP_ONLY(static_assert(std::is_same::value, "")); // Implementation detail + + static_assert( + E::auto_format != E::native_format && + E::auto_format != E::generic_format && + E::native_format != E::generic_format, + "Expected enumeration values are not unique"); +} diff --git a/www/cxx1z_status.html b/www/cxx1z_status.html index 93d6b046a..a28fcd800 100644 --- a/www/cxx1z_status.html +++ b/www/cxx1z_status.html @@ -149,7 +149,7 @@ P0270R3CWGRemoving C dependencies from signal handler wordingKona P0298R3CWGA byte type definitionKonaComplete5.0 P0317R1LWGDirectory Entry Caching for FilesystemKona - P0430R2LWGFile system library on non-POSIX-like operating systemsKona + P0430R2LWGFile system library on non-POSIX-like operating systemsKonaComplete7.0 P0433R2LWGToward a resolution of US7 and US14: Integrating template deduction for class templates into the standard libraryKonaIn progress7.0 P0452R1LWGUnifying <numeric> Parallel AlgorithmsKona P0467R2LWGIterator Concerns for Parallel AlgorithmsKona