Implement modified LWG 2665
authorEric Fiselier <eric@efcs.ca>
Sat, 15 Oct 2016 22:37:42 +0000 (22:37 +0000)
committerEric Fiselier <eric@efcs.ca>
Sat, 15 Oct 2016 22:37:42 +0000 (22:37 +0000)
llvm-svn: 284313

libcxx/include/experimental/filesystem
libcxx/src/experimental/filesystem/path.cpp
libcxx/test/std/experimental/filesystem/class.path/path.member/path.modifiers/remove_filename.pass.cpp
libcxx/www/upcoming_meeting.html

index 45de0d1..c1427c8 100644 (file)
@@ -863,7 +863,15 @@ public:
     }
 
     path& make_preferred() { return *this; }
-    path& remove_filename() { return *this = parent_path(); }
+
+    _LIBCPP_INLINE_VISIBILITY
+    path& remove_filename() {
+      if (__pn_.size() == __root_path_raw().size())
+        clear();
+      else
+        __pn_ = __parent_path();
+      return *this;
+    }
 
     path& replace_filename(const path& __replacement) {
         remove_filename();
@@ -925,6 +933,7 @@ private:
     _LIBCPP_FUNC_VIS int __compare(__string_view) const;
     _LIBCPP_FUNC_VIS __string_view __root_name() const;
     _LIBCPP_FUNC_VIS __string_view __root_directory() const;
+    _LIBCPP_FUNC_VIS __string_view __root_path_raw() const;
     _LIBCPP_FUNC_VIS __string_view __relative_path() const;
     _LIBCPP_FUNC_VIS __string_view __parent_path() const;
     _LIBCPP_FUNC_VIS __string_view __filename() const;
@@ -953,7 +962,7 @@ public:
 
     _LIBCPP_INLINE_VISIBILITY bool has_root_name()      const { return !__root_name().empty(); }
     _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const { return !__root_directory().empty(); }
-    _LIBCPP_INLINE_VISIBILITY bool has_root_path()      const { return !(__root_name().empty() && __root_directory().empty()); }
+    _LIBCPP_INLINE_VISIBILITY bool has_root_path()      const { return !__root_path_raw().empty(); }
     _LIBCPP_INLINE_VISIBILITY bool has_relative_path()  const { return !__relative_path().empty(); }
     _LIBCPP_INLINE_VISIBILITY bool has_parent_path()    const { return !__parent_path().empty(); }
     _LIBCPP_INLINE_VISIBILITY bool has_filename()       const { return !__filename().empty(); }
index 22ad23b..64da302 100644 (file)
@@ -277,6 +277,16 @@ string_view_t path::__root_directory() const
     return parser::extract_preferred(__pn_, start_i);
 }
 
+string_view_t path::__root_path_raw() const
+{
+    size_t e = parser::root_directory_end(__pn_);
+    if (!parser::good(e))
+      e = parser::root_name_end(__pn_);
+    if (parser::good(e))
+      return string_view_t{__pn_}.substr(0, e + 1);
+    return {};
+}
+
 string_view_t path::__relative_path() const
 {
     if (empty()) {
index 4ad9084..e414202 100644 (file)
@@ -35,16 +35,24 @@ const RemoveFilenameTestcase TestCases[] =
   {
       {"", ""}
     , {"/", ""}
+    , {"//", ""}
+    , {"///", ""}
     , {"\\", ""}
     , {".", ""}
     , {"..", ""}
     , {"/foo", "/"}
+    , {"//foo", ""}
+    , {"//foo/", ""}
+    , {"//foo///", ""}
+    , {"///foo", "/"}
+    , {"///foo/", "///foo"}
     , {"/foo/", "/foo"}
     , {"/foo/.", "/foo"}
     , {"/foo/..", "/foo"}
     , {"/foo/////", "/foo"}
     , {"/foo\\\\", "/"}
     , {"/foo//\\/", "/foo//\\"}
+    , {"///foo", "/"}
     , {"file.txt", ""}
     , {"bar/../baz/./file.txt", "bar/../baz/."}
   };
index e0d53bd..4b58c7e 100644 (file)
@@ -89,7 +89,7 @@
         <tr><td><a href="http://wg21.link/LWG2591">2591</a></td><td>std::function's member template target() should not lead to undefined behaviour</td><td>Issaquah</td><td></td></tr>
         <tr><td><a href="http://wg21.link/LWG2598">2598</a></td><td>addressof works on temporaries</td><td>Issaquah</td><td>Patch ready</td></tr>
         <tr><td><a href="http://wg21.link/LWG2664">2664</a></td><td>operator/ (and other append) semantics not useful if argument has root</td><td>Issaquah</td><td>Nothing to do</td></tr>
-        <tr><td><a href="http://wg21.link/LWG2665">2665</a></td><td>remove_filename() post condition is incorrect</td><td>Issaquah</td><td></td></tr>
+        <tr><td><a href="http://wg21.link/LWG2665">2665</a></td><td>remove_filename() post condition is incorrect</td><td>Issaquah</td><td>See Below</td></tr>
         <tr><td><a href="http://wg21.link/LWG2672">2672</a></td><td>Should is_empty use error_code in its specification?</td><td>Issaquah</td><td></td></tr>
         <tr><td><a href="http://wg21.link/LWG2678">2678</a></td><td>std::filesystem enum classes overspecified</td><td>Issaquah</td><td>Nothing to do</td></tr>
         <tr><td><a href="http://wg21.link/LWG2679">2679</a></td><td>Inconsistent Use of Effects and Equivalent To</td><td>Issaquah</td><td>Nothing to do</td></tr>
 <li>2591 - I <b>suspect</b> that this is just better specification of the existing structure. Probably need more tests for this.</li>
 <li>2598 - Patch and tests ready</li>
 <li>2664 - No change needed. _LIBCPP_DEBUG mode tests the new requirements.</li>
-<li>2665 - File System; Eric?</li>
+<li>2665 - PR is incorrect as-is. We implement a modified version</li>
 <li>2672 - File System; Eric?</li>
 <li>2678 - File System; Eric?</li>
 <li>2679 - This is just wording cleanup. </li>