Fix handling of an empty filename at end of a path
commit048233284d305d7ec4000f3e594bf01ffb248a25
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 23 May 2018 16:11:06 +0000 (23 16:11 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 23 May 2018 16:11:06 +0000 (23 16:11 +0000)
treeef3d41a212735827f10935b6954e5389c86704c2
parent53c9a2d5a6f698c5f48c6e80c3958ac5064f1e58
Fix handling of an empty filename at end of a path

The C++17 std::filesystem::path grammar allows an empty filename as the
last component (to signify a trailing slash). The existing code does not
handle this consistently, sometimes an empty filename has type _Multi
and sometimes it has type _Filename. This can result in a non-empty
iterator range for an empty filename component.

This change ensures that empty paths always have type _Filename and will
yield an empty iterator range.

* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@260616 138bc75d-0d04-0410-961f-82ee72b054a4
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/fs_path.h
libstdc++-v3/src/filesystem/std-path.cc
libstdc++-v3/testsuite/27_io/filesystem/path/itr/components.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/filesystem/path/itr/traversal.cc