From patchwork Fri Oct 28 14:24:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 79939 Delivered-To: patch@linaro.org Received: by 10.80.142.83 with SMTP id 19csp1236792edx; Fri, 28 Oct 2016 07:25:27 -0700 (PDT) X-Received: by 10.99.133.200 with SMTP id u191mr21293482pgd.28.1477664727742; Fri, 28 Oct 2016 07:25:27 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id l67si13840916pfj.124.2016.10.28.07.25.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Oct 2016 07:25:27 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439833-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-439833-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439833-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=gJP/FAvW3vSQVIxfL3sd3vvMNu+I3LT8TdlAgv35NqjilpzwtsGub i/rTgmHE2dOfL6EBmN0eEDqJmnJd/BPullJldDpozoYcFJr38tt6xpPrVKixHZm8 F2WCEXpLaxtp1N6W6QPoNhYQAdAtrkVIGvZoW9sEWKFdcl7+hCW0ho= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=3fUOCKAfa1ViIsCchWYDgNHnk2E=; b=fFKC9mAdCfp87AJrRAq2 Cb7JYubrh3bzl8wzGL9mX1MzZbkJ55oCX9kk0q3eGvLT0nRTOGwdHTzovb/PKgz1 t8uphj0myF/eQy23k59CcQl/Mc5AooTpVjtRS82Rmnwo0ggj4RNew+o2exYVGAk9 /z4w4MUd3TVlhbRgfqOBNqI= Received: (qmail 25871 invoked by alias); 28 Oct 2016 14:25:00 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 25842 invoked by uid 89); 28 Oct 2016 14:24:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=36, 7, 52, 9, system_error, fsa X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 28 Oct 2016 14:24:49 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0106B6333C; Fri, 28 Oct 2016 14:24:48 +0000 (UTC) Received: from localhost (ovpn-116-30.ams2.redhat.com [10.36.116.30]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9SEOjCg014162; Fri, 28 Oct 2016 10:24:47 -0400 Date: Fri, 28 Oct 2016 15:24:45 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] Implement std::filesystem for C++17 Message-ID: <20161028142445.GH2922@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.0 (2016-08-17) Here's a patch to move std::experimental::filesystem to std::filesystem, and then add using declarations to pull it all back into std::experimental::filesystem. The definitions are still in the separate libstdc++fs.a archive, not in libstdc++.so, and I plan to keep it that for GCC 7, because there are some changes likely to happen to the spec that might affect the API and ABI. I'll probably commit this in about a week, during the Issaquah meeting. commit a287ae40c1cb242f5b56b0d12eef4464704292d0 Author: Jonathan Wakely Date: Fri Oct 21 13:57:32 2016 +0100 std::filesystem diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml index a1190bc..a01fa86 100644 --- a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml +++ b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml @@ -662,14 +662,13 @@ Feature-testing recommendations for C++. - Adopt the File System TS for C++17 P0218R1 - No + 7 __has_include(<filesystem>) , __cpp_lib_filesystem >= 201603 diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 15a164e..cfd82bd 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -36,6 +36,7 @@ std_headers = \ ${std_srcdir}/complex \ ${std_srcdir}/condition_variable \ ${std_srcdir}/deque \ + ${std_srcdir}/filesystem \ ${std_srcdir}/forward_list \ ${std_srcdir}/fstream \ ${std_srcdir}/functional \ diff --git a/libstdc++-v3/include/experimental/bits/fs_dir.h b/libstdc++-v3/include/experimental/bits/fs_dir.h index 70a95eb..b42fec7 100644 --- a/libstdc++-v3/include/experimental/bits/fs_dir.h +++ b/libstdc++-v3/include/experimental/bits/fs_dir.h @@ -40,11 +40,9 @@ namespace std _GLIBCXX_VISIBILITY(default) { -namespace experimental -{ namespace filesystem { -inline namespace v1 +inline namespace __fs1 { _GLIBCXX_BEGIN_NAMESPACE_VERSION @@ -353,9 +351,8 @@ _GLIBCXX_END_NAMESPACE_CXX11 // @} group filesystem _GLIBCXX_END_NAMESPACE_VERSION -} // namespace v1 +} // namespace __fs1 } // namespace filesystem -} // namespace experimental } // namespace std #endif // C++11 diff --git a/libstdc++-v3/include/experimental/bits/fs_fwd.h b/libstdc++-v3/include/experimental/bits/fs_fwd.h index fb8521a..ad17465 100644 --- a/libstdc++-v3/include/experimental/bits/fs_fwd.h +++ b/libstdc++-v3/include/experimental/bits/fs_fwd.h @@ -40,11 +40,9 @@ namespace std _GLIBCXX_VISIBILITY(default) { -namespace experimental -{ namespace filesystem { -inline namespace v1 +inline namespace __fs1 { #if _GLIBCXX_INLINE_VERSION inline namespace __7 { } @@ -283,9 +281,8 @@ _GLIBCXX_END_NAMESPACE_CXX11 // @} group filesystem _GLIBCXX_END_NAMESPACE_VERSION -} // namespace v1 +} // namespace __fs1 } // namespace filesystem -} // namespace experimental } // namespace std #endif // C++11 diff --git a/libstdc++-v3/include/experimental/bits/fs_ops.h b/libstdc++-v3/include/experimental/bits/fs_ops.h index 62a9826..9ff300d 100644 --- a/libstdc++-v3/include/experimental/bits/fs_ops.h +++ b/libstdc++-v3/include/experimental/bits/fs_ops.h @@ -38,11 +38,9 @@ namespace std _GLIBCXX_VISIBILITY(default) { -namespace experimental -{ namespace filesystem { -inline namespace v1 +inline namespace __fs1 { _GLIBCXX_BEGIN_NAMESPACE_VERSION @@ -287,9 +285,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // @} group filesystem _GLIBCXX_END_NAMESPACE_VERSION -} // namespace v1 +} // namespace __fs1 } // namespace filesystem -} // namespace experimental } // namespace std #endif // C++11 diff --git a/libstdc++-v3/include/experimental/bits/fs_path.h b/libstdc++-v3/include/experimental/bits/fs_path.h index 4d7291f..35d39dc 100644 --- a/libstdc++-v3/include/experimental/bits/fs_path.h +++ b/libstdc++-v3/include/experimental/bits/fs_path.h @@ -52,11 +52,9 @@ namespace std _GLIBCXX_VISIBILITY(default) { -namespace experimental -{ namespace filesystem { -inline namespace v1 +inline namespace __fs1 { _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_BEGIN_NAMESPACE_CXX11 @@ -337,6 +335,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 bool is_absolute() const; bool is_relative() const { return !is_absolute(); } +#if __cplusplus > 201402L + // TODO generation + path lexically_normal() const; + path lexically_relative(const path& __base) const; + path lexically_proximate(const path& __base) const; +#endif + // iterators class iterator; typedef iterator const_iterator; @@ -1028,9 +1033,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 // @} group filesystem _GLIBCXX_END_NAMESPACE_CXX11 _GLIBCXX_END_NAMESPACE_VERSION -} // namespace v1 +} // namespace __fs1 } // namespace filesystem -} // namespace experimental } // namespace std #endif // C++11 diff --git a/libstdc++-v3/include/experimental/filesystem b/libstdc++-v3/include/experimental/filesystem index e13c428..c12ed4e 100644 --- a/libstdc++-v3/include/experimental/filesystem +++ b/libstdc++-v3/include/experimental/filesystem @@ -48,25 +48,69 @@ namespace experimental { namespace filesystem { -inline namespace v1 -{ -_GLIBCXX_BEGIN_NAMESPACE_VERSION - - /** - * @ingroup filesystem - */ - inline std::string filesystem_error::_M_gen_what() - { - std::string __what = "filesystem error: "; - __what += system_error::what(); - if (!_M_path1.empty()) - __what += " [" + _M_path1.string() + ']'; - if (!_M_path2.empty()) - __what += " [" + _M_path2.string() + ']'; - return __what; - } - -_GLIBCXX_END_NAMESPACE_VERSION +inline namespace v1 { + using ::std::filesystem::path; + using ::std::filesystem::swap; + using ::std::filesystem::hash_value; + using ::std::filesystem::operator==; + using ::std::filesystem::operator!=; + using ::std::filesystem::operator<; + using ::std::filesystem::operator<=; + using ::std::filesystem::operator>; + using ::std::filesystem::operator>=; + using ::std::filesystem::operator/; + using ::std::filesystem::operator<<; + using ::std::filesystem::operator>>; + using ::std::filesystem::u8path; + using ::std::filesystem::filesystem_error; + using ::std::filesystem::directory_entry; + using ::std::filesystem::directory_iterator; + using ::std::filesystem::begin; + using ::std::filesystem::end; + using ::std::filesystem::recursive_directory_iterator; + using ::std::filesystem::file_status; + using ::std::filesystem::space_info; + using ::std::filesystem::file_type; + using ::std::filesystem::perms; + using ::std::filesystem::copy_options; + using ::std::filesystem::directory_options; + using ::std::filesystem::file_time_type; + using ::std::filesystem::absolute; + using ::std::filesystem::canonical; + using ::std::filesystem::copy; + using ::std::filesystem::copy_file; + using ::std::filesystem::copy_symlink; + using ::std::filesystem::create_directories; + using ::std::filesystem::create_directory; + using ::std::filesystem::create_hard_link; + using ::std::filesystem::create_symlink; + using ::std::filesystem::current_path; + using ::std::filesystem::exists; + using ::std::filesystem::equivalent; + using ::std::filesystem::file_size; + using ::std::filesystem::hard_link_count; + using ::std::filesystem::is_block_file; + using ::std::filesystem::is_character_file; + using ::std::filesystem::is_directory; + using ::std::filesystem::is_empty; + using ::std::filesystem::is_fifo; + using ::std::filesystem::is_other; + using ::std::filesystem::is_regular_file; + using ::std::filesystem::is_socket; + using ::std::filesystem::is_symlink; + using ::std::filesystem::last_write_time; + using ::std::filesystem::permissions; + using ::std::filesystem::read_symlink; + using ::std::filesystem::remove; + using ::std::filesystem::remove_all; + using ::std::filesystem::rename; + using ::std::filesystem::resize_file; + using ::std::filesystem::space; + using ::std::filesystem::status; + using ::std::filesystem::status_known; + using ::std::filesystem::symlink_status; + using ::std::filesystem::system_complete; + using ::std::filesystem::temp_directory_path; } // namespace v1 } // namespace filesystem } // namespace experimental diff --git a/libstdc++-v3/src/filesystem/dir.cc b/libstdc++-v3/src/filesystem/dir.cc index bcd7dd0..29ec567 100644 --- a/libstdc++-v3/src/filesystem/dir.cc +++ b/libstdc++-v3/src/filesystem/dir.cc @@ -45,7 +45,7 @@ # define opendir _wopendir #endif -namespace fs = std::experimental::filesystem; +namespace fs = std::filesystem; struct fs::_Dir { diff --git a/libstdc++-v3/src/filesystem/ops.cc b/libstdc++-v3/src/filesystem/ops.cc index 9abcee0..2746054 100644 --- a/libstdc++-v3/src/filesystem/ops.cc +++ b/libstdc++-v3/src/filesystem/ops.cc @@ -62,7 +62,7 @@ # define chmod _wchmod #endif -namespace fs = std::experimental::filesystem; +namespace fs = std::filesystem; fs::path fs::absolute(const path& p, const path& base) diff --git a/libstdc++-v3/src/filesystem/path.cc b/libstdc++-v3/src/filesystem/path.cc index f6505fd..9fc8579 100644 --- a/libstdc++-v3/src/filesystem/path.cc +++ b/libstdc++-v3/src/filesystem/path.cc @@ -28,9 +28,21 @@ #include -using std::experimental::filesystem::path; +namespace fs = std::filesystem; +using std::filesystem::path; -std::experimental::filesystem::filesystem_error::~filesystem_error() = default; +fs::filesystem_error::~filesystem_error() = default; + +std::string fs::filesystem_error::_M_gen_what() +{ + std::string __what = "filesystem error: "; + __what += system_error::what(); + if (!_M_path1.empty()) + __what += " [" + _M_path1.string() + ']'; + if (!_M_path2.empty()) + __what += " [" + _M_path2.string() + ']'; + return __what; +} constexpr path::value_type path::preferred_separator; @@ -461,7 +473,7 @@ path::_S_convert_loc(const char* __first, const char* __last, } std::size_t -std::experimental::filesystem::hash_value(const path& p) noexcept +fs::hash_value(const path& p) noexcept { // [path.non-member] // "If for two paths, p1 == p2 then hash_value(p1) == hash_value(p2)."