+2018-05-23 Jonathan Wakely <jwakely@redhat.com>
+
+ * include/bits/fs_path.h (path::_M_type): Change default member
+ initializer to _Filename.
+ (path::begin): Create past-the-end iterator for empty path.
+ * src/filesystem/std-path.cc (path::remove_filename()): Remove
+ debugging check.
+ (path::has_relative_path()): Return false for empty filenames.
+ (path::_M_split_cmpts): Set _M_type to _Filename for empty paths.
+ Fix offset of empty final component.
+ * testsuite/27_io/filesystem/path/itr/components.cc: New.
+ * testsuite/27_io/filesystem/path/itr/traversal.cc: Add new inputs.
+
2018-05-21 Jonathan Wakely <jwakely@redhat.com>
Add support for opening file streams from wide character strings.
struct _Cmpt;
using _List = _GLIBCXX_STD_C::vector<_Cmpt>;
_List _M_cmpts; // empty unless _M_type == _Type::_Multi
- _Type _M_type = _Type::_Multi;
+ _Type _M_type = _Type::_Filename;
};
template<>
{
if (_M_type == _Type::_Multi)
return iterator(this, _M_cmpts.begin());
- return iterator(this, false);
+ return iterator(this, empty());
}
inline path::iterator
}
else if (_M_type == _Type::_Filename)
clear();
- if (!empty() && _M_pathname.back() != '/')
- throw 1;
return *this;
}
bool
path::has_relative_path() const
{
- if (_M_type == _Type::_Filename)
+ if (_M_type == _Type::_Filename && !_M_pathname.empty())
return true;
if (!_M_cmpts.empty())
{
++__it;
if (__it != _M_cmpts.end() && __it->_M_type == _Type::_Root_dir)
++__it;
- if (__it != _M_cmpts.end())
+ if (__it != _M_cmpts.end() && !__it->_M_pathname.empty())
return true;
}
return false;
void
path::_M_split_cmpts()
{
- _M_type = _Type::_Multi;
_M_cmpts.clear();
-
if (_M_pathname.empty())
- return;
+ {
+ _M_type = _Type::_Filename;
+ return;
+ }
+ _M_type = _Type::_Multi;
size_t pos = 0;
const size_t len = _M_pathname.size();
// An empty element, if trailing non-root directory-separator present.
if (_M_cmpts.back()._M_type == _Type::_Filename)
{
- const auto& last = _M_cmpts.back();
- pos = last._M_pos + last._M_pathname.size();
+ pos = _M_pathname.size();
_M_cmpts.emplace_back(string_type(), _Type::_Filename, pos);
}
}
--- /dev/null
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17 -lstdc++fs" }
+// { dg-do run { target c++17 } }
+// { dg-require-filesystem-ts "" }
+
+#include <filesystem>
+#include <iterator>
+#include <testsuite_hooks.h>
+#include <testsuite_fs.h>
+
+void
+test01()
+{
+ for (std::filesystem::path p : __gnu_test::test_paths)
+ {
+ if (p.empty())
+ VERIFY(std::distance(p.begin(), p.end()) == 0);
+ else
+ VERIFY(std::distance(p.begin(), p.end()) != 0);
+
+ for (const std::filesystem::path& cmpt : p)
+ {
+ if (cmpt.empty())
+ VERIFY(std::distance(cmpt.begin(), cmpt.end()) == 0);
+ else
+ VERIFY(std::distance(cmpt.begin(), cmpt.end()) == 1);
+ }
+ }
+}
+
+int
+main()
+{
+ test01();
+}
void
test03()
{
- path paths[] = { "single", "multiple/elements" };
+ path paths[] = { "single", "multiple/elements", "trailing/slash/", "/." };
for (const path& p : paths)
for (auto iter = p.begin(); iter != p.end(); ++iter)
{